SQL2005中CURSOR的用法举例
--声明游标,admin是一个表的名称,该游标标识了该表中的属性名称DECLARE Column_Name CURSOR FOR SELECT name FROM sys.columns WHERE object_id = object_id('admin');--打开游标OPEN Column_Name;DECLARE @Column_Name VARCHAR(100)--从游标中获...
--声明游标,admin是一个表的名称,该游标标识了该表中的属性名称
DECLARE Column_Name CURSOR FOR SELECT name FROM sys.columns WHERE object_id = object_id('admin');
--打开游标
OPEN Column_Name;
DECLARE @Column_Name VARCHAR(100)
--从游标中获取数据,
FETCH Column_Name INTO @Column_Name
--WHILE循环,遍历游标,当@@FETCH_STATUS为0时,表示游标遍历完毕
WHILE(@@FETCH_STATUS = 0)
BEGIN
--打印记录
PRINT(@Column_name)
--获取下一条记录
FETCH NEXT FROM Column_Name INTO @Column_Name;
END
--关闭游标
CLOSE Column_Name
--删除游标
DEALLOCATE Column_Name
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/jetcui1/archive/2008/08/23/2818751.aspx
更多推荐
所有评论(0)