您的位置:首页 >> 数据库 >> Oracle >> 正文
Oracle RSS
 

详细介绍两种动态定义游标的方法

http://www.rdxx.com 07年11月20日 00:00 我要投稿

关键词: 游标 , 方法 , 动态

  方法一:

  不知道多输出参数如何写:

     declare @cursor_name varchar(36),@str nvarchar(4000)
select  @cursor_name=newid() 
DECLARE @ckbm varchar(20) 
exec('DECLARE ['+@cursor_name + '] CURSOR FOR select f_ckbm from tbda_ck')
exec('open ['+ @cursor_name+']')
set @str=N'fetch from ['+ @cursor_name +'] into @ckbm'
exec sp_executesql @str,N'@ckbm varchar(20) out',@ckbm out
while @@fetch_status = 0 
begin
    print @ckbm
    exec sp_executesql @str,N'@ckbm varchar(20) out',@ckbm out
end
exec('close ['+ @cursor_name+']')
exec('deallocate ['+ @cursor_name+']')

  方法二:

  可以实现多输出参数

declare @sqlExec varchar(8000),@tableName varchar(255),@myvar varchar(20) 
  set @tableName = 'Checkbag_info' 
  set @sqlExec = 'declare cursor1 cursor for ' + CHAR(13) 
  set @sqlExec = @sqlExec + ' select res_sort from ' + @tableName 
  exec(@sqlExec) 
  open cursor1 
  fetch next from cursor1 into @myvar 
  while @@fetch_status = 0 
  begin 
  print @myvar 
  fetch next from cursor1 into @myvar 
  end 
  close cursor1 
  deallocate cursor1


 
 
标签: 游标 , 方法 , 动态 打印本文
 
 
  热点搜索
 
 
 



Valid XHTML 1.0 Transitional
Copyright ©2005 - 2008 Rdxx.Com,All Rights Reserved
收藏本页
收藏本站