用游标来查找数据例子:

第一种方式
-定义游标text_cursor 关联表t_icitem 基表
declare text_cursor cursor scroll
for select * from t_icitem 
--打开游标text_cursor
open text_cursor
--读取游标 第一行(first) 在text_cursor游标中
fetch first from text_cursor
--关闭游标text_cursor
close text_cursor
--释放(删除)游标,释放资源
deallocate text_cursor

第二种方式
declare @var_cursor  cursor  
set @var_cursor=cursor scroll for select * from t_icitem 
open @var_cursor
fetch last from @var_cursor
close @var_cursor
deallocate @var_cursor
原文地址:https://www.cnblogs.com/xiaowie/p/8676209.html