遊標使用方法

遊標使用方法:
use db1
declare my_cursor cursor scroll dynamic /*scroll表示可隨意移動遊標指針(否則只能向前),dynamic表示可以讀寫遊標(否則遊標只讀)*/
for
select 姓名 from 個人資料

open my_cursor
declare @name sysname
fetch next from my_cursor into @name
while(@@fetch_status=0)
  begin
    print '姓名: ' + @name
    fetch next from my_cursor into @name
  end
fetch first from my_cursor into @name
print @name
/* update 個人資料 set 姓名='zzg' where current of my_cursor */
/* delete from 個人資料 where current of my_cursor */
close my_cursor
deallocate my_cursor

h first from my_cursor into @name
print @name
/* update 個人資料 set 姓名='zzg' where current of my_cursor */
/* delete from 個人資料 where current of my_cursor */
close my_cursor
deallocate my_cursor
發佈了32 篇原創文章 · 獲贊 1 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章