现在的位置: 首页 > 综合 > 正文

游标的使用

2018年02月12日 ⁄ 综合 ⁄ 共 300字 ⁄ 字号 评论关闭

遍历某个表时要用到游标
declare HistoryCur cursor for
select _order,dataitemid from #idlist;
declare @tablename varchar(50);
declare @itemid int;
open HistoryCur;
fetch next from HistoryCur into @tablename,@itemid;
while(@@fetch_status <> -1) --等于 -1表示没有遍历完成
begin
 --对@tablename,@itemid进行操作
 fetch next from HistoryCur into @tablename,@itemid;
end

抱歉!评论已关闭.