SQL SREVER如何创建和使用动态游标
2008-01-28 09:51:38 来源:WEB开发网核心提示: 使用游标/注:在SELECT中有几项,fetch from @cursor_name into @cust_id就应该声明几个变量,而且顺序和类型必须一致.*/declare @cursor_name cursor,@select_command varchar(8000),@cust_i
使用游标
/注:在SELECT中有几项,fetch from @cursor_name into @cust_id就应该声明几个变量,而且顺序和类型必须一致.*/
declare @cursor_name cursor,
@select_command varchar(8000),
@cust_id varchar(20)
select @select_command = 'select cust_id from so_cust'
execute usp_createcursor @select_command,@cursor_name OUTPUT
fetch from @cursor_name into @cust_id
while @@fetch_status = 0
begin
fetch from @cursor_name into @cust_id
end
close @cursor_name
deallocate cursor_name
说明:上述代码在MSS SQL Server7.0上通过。其它数据库只需修改一下抓取栏位及其类型的系统表就可以了。
更多精彩
赞助商链接