sql 遊標循環

declare  @id int,@value nvarchar(100);
begin
    declare c_test_main cursor fast_forward for select hps_hpId,hps_time  from  hospitalPermSupp where hps_usId=1;
    open c_test_main;--打開遊標
    while 1=1 --開始循環
    begin
        fetch next from c_test_main into @id,@value; --賦值到變量中
        if(@@fetch_status!=0)break;--如果沒有結果退出循環
        select @id as a,@value as b
    end
    close c_test_main    --關閉遊標
    deallocate c_test_main    --釋放遊標
end

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章