声明一个cursor时,for后边可以是一个变量码?请教,急!!!!!!

cshgood1 2003-08-21 04:18:23
声明一个cursor时,for后边可以是一个变量码?请教,急!!!!!!

一般情况:
declare cursorName cursor for select * from tableName

现在我的情况时:我的select语句时一个变量
@va = 'select * from tableName'
我如何使用游标呀????:((

...全文
25 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
cshgood1 2003-08-21
  • 打赏
  • 举报
回复
谢谢大家
问题解决了
pengdali(大力 V2.0)
的方法是对得
pengdali 2003-08-21
  • 打赏
  • 举报
回复
exec('declare cursor_insert cursor for select c# from cs')

--注意:只有声明的时候是动态的。
declare @i int
open cursor_insert
fetch cursor_insert into @i
while @@fetch_status=0
begin
print @i
fetch cursor_insert into @i
end
close cursor_insert
deallocate cursor_insert
cshgood1 2003-08-21
  • 打赏
  • 举报
回复
我实在sql server 2000
遇到的问题
请教各位能不能格我个例子
tcmis 2003-08-21
  • 打赏
  • 举报
回复
cursor curName(strCondition VARCHAR2) is select * from table_name;
rowValue curName%rowType;

FOR rowValue IN curName(..) LOOP
....
END LOOP;
happydreamer 2003-08-21
  • 打赏
  • 举报
回复
有变量时用动态sql做
amtyuranus 2003-08-21
  • 打赏
  • 举报
回复
动态的sql语句就可以了
CrazyFor 2003-08-21
  • 打赏
  • 举报
回复
看联机帮助中是不允许用变更的,只有用动太SQL主句执行了.如:

exec('
declare cursorName cursor for '+@SQL+'...
..
....

')
就是比较烦.
eastpond 2003-08-21
  • 打赏
  • 举报
回复
不好意思,上面的是在pb里的语法
eastpond 2003-08-21
  • 打赏
  • 举报
回复
declare art dynamic cursor for sqlsa;

ls_sqltxt='select c_articleid,c_articlename,c_unit,c_cprice,c_bprice,c_zprice'&
+' from xt_article where (c_typecode = ?) and (c_brandcode = ?) and (c_breedcode = ?) and ((c_mpcode is null) or (c_mpcode like ' + "'%'" + ')) and not (c_brandcode is null)'
prepare sqlsa from :ls_sqltxt;
open dynamic art using :is_typecode,:is_brandcode,:is_breedcode;
eastpond 2003-08-21
  • 打赏
  • 举报
回复
declare art dynamic cursor for sqlsa;

ls_sqltxt='select c_articleid,c_articlename,c_unit,c_cprice,c_bprice,c_zprice'&
+' from xt_article where (c_typecode = ?) and (c_brandcode = ?) and (c_breedcode = ?) and ((c_mpcode is null) or (c_mpcode like ' + "'%'" + ')) and not (c_brandcode is null)'
prepare sqlsa from :ls_sqltxt;
open dynamic art using :is_typecode,:is_brandcode,:is_breedcode;

22,207

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧