--資料指標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 --釋放掉指標,因為他在用的時候會佔資源

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 花花 的頭像
    花花

    百花

    花花 發表在 痞客邦 留言(0) 人氣()