乙個游標簡單示例

2021-08-30 20:22:41 字數 889 閱讀 8229

下面是乙個游標的例項,方便初學者學習,也可以防止自己忘記 。

if exists(select 1 from sysobjects where [name] = 'hehe')

drop procedure hehe

goset ansi_nulls on

set quoted_identifier on

gocreate procedure hehe

asbegin

--建立游標

declare xqyg_zs_cursor cursor local scroll dynamic --宣告乙個可迴圈操作的游標

for select [name] from tablename

open xqyg_zs_cursor --開啟游標

declare @words_list sysname --詞彙

fetch next from xqyg_zs_cursor into @words_list --游標移到第乙個記錄

while(@@fetch_status = 0) --檢查游標是不是最後乙個,如果不是則進行中間的程式

begin

--一段處理程式段

insert into testhe(id,[name],[password],[address])

values('1','jj','963',@words_list)

fetch next from xqyg_zs_cursor into @words_list --游標移到下乙個記錄

endclose xqyg_zs_cursor --關閉游標

deallocate xqyg_zs_cursor --釋放游標

end--exec hehe

--select * from testhe

Sqlserver 游標簡單示例

建立乙個游標 declare my cursor cursor for my cursor為游標的名稱,隨便起 select id,name from my user 這是游標my cursor的值,這裡隨便發揮看業務場景 開啟游標 open my cursor 沒什麼好說的 變數 declare ...

乙個簡單的學習示例

bob bob smith 42,30000,software sue sue jones 45,40000,hardware print bob 0 sue 2 print n print bob 0 split 1 sue 2 1.25 print n print sue people bob,...

乙個簡單網路爬蟲示例

在學生時期,可能聽到網路爬蟲這個詞會覺得很高大上,但是它的簡單實現可能學生都不難懂。網路爬蟲應用,就是把整個網際網路真的就當做一張網,像蜘蛛網那樣,應用就像乙個蟲子,在網上面按照一定的規則爬動。現在網際網路應用最廣的就是http s 協議了,本文例子就是基於使用http s 協議的,只作為示例,不涉...