--資料指標cursor
declare stucursor cursor --宣告資料指標
static --靜態資料指標
for select 學號,姓名,電話 from 學生 --給學生資料表使用cursor
open stucursor
declare @id char(4),@name varchar(12),@tel varchar(15)
fetch first from stucursor into @id,@name,@tel --把資料指標移到第一筆資料
while @@FETCH_STATUS=0 --有收到0代表有收到資料,收到-1代表沒有資料
begin
print 'id='+@id+',name='+@name+',tel='+@tel
fetch next from stucursor into @id,@name,@tel
end
close stucursor
deallocate stucursor --釋放掉指標,因為他在用的時候會佔資源
全站熱搜
留言列表