亚洲女同成aV人片在线观看|亚洲www啪成人一区二区麻豆|亚洲国产中日韩精品综合|亚洲国产成人精品一级片|亚洲无码在线视频免费

新聞中心

NEWS

詳解SQL游標的用法

時(shí)間:2026-05-05 03:12:01

這篇文章主要介紹了SQL游標的詳解用法,文中講解非常詳細,游用法配合代碼幫助大家更好的詳解理解學(xué)習,感興趣的游用法朋友可以了解下

類(lèi)型:

1.普通游標 只有NEXT操作(zuo)

2.滾動(dòng)游標 有多種操作

1.普通游標

DECLARE @username varchar(20),@UserId varchar(100)
DECLARE cursor(′?`)_name CURSOR FOR --定義游標
SELECT TOP 10 UserId,UserName FROM UserIn┐(′ー`)┌fo
ORDER BY UserId DESC
OP??EN cursor_name --打開(kāi)游(′;д;`)標
FETCH NEXT FROM cursor_name?? INTO @UserId,@usern(′▽?zhuān)?)ame --抓取下一行游標數據
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT '用(yong)戶(hù)ID:'+@UserId+' '+'用戶(hù)名:'+@username

FETCH NEXT FROM cursor_name INTO @UserId,@username
END
CLOSE cursor_name --關(guān)閉游標
DEALLOCATE cursor_n??ame --釋放游標

結果:

用戶(hù)ID:zhizhi 用戶(hù)名:鄧鴻芝

用戶(hù)ID:yuyu 用戶(hù)名:魏雨

用戶(hù)ID:yujie 用戶(hù)名:李玉杰

用戶(hù)ID:yuanyuaˉ\_(ツ)_/ˉn 用戶(hù)名:王夢(mèng)緣

用戶(hù)ID:YOUYOU 用戶(hù)名:lisi( ?° ?? ?°)

用戶(hù)ID:yiyiren 用戶(hù)名:任毅

用戶(hù)ID:yanbo 用戶(hù)名:王艷波

用戶(hù)ID:xuxu 用戶(hù)名:陳佳緒

用戶(hù)ID:??xiangxiang 用戶(hù)名:李慶祥

用戶(hù)ID:wenwen 用戶(hù)名:魏文文

2.滾動(dòng)游標

--帶SCROLL選項的游標
SET NOCOUNT ON
DECLARE C SCROLL CURSOR FOR --SCORLL 后,有了更多的詳解┐(′?`)┌游標操作(滾動(dòng)游標)
SELECT TOP 10 UserId,UserName FROM UserInfo
ORDER BY UserId DESC
open="open" C
FETCH LAST FROM C --最后一行的數據,并將當前行為指定行
FETCH ABSOLUTE 4 FROM C --從第一行開(kāi)始的游用法第4行??數據,并將當前行為指定行 這里的詳解n可正可負,n>0 往下翻,游用法n<??;0 往上翻
FETCH RELATIVE 3 FROM C --相對于當前行的詳解后3行數據,并將當前行為指定??(ding)行 這里??的游用法n可正可負
FETC??H RELATIV(′?`*)E -2 FROM C --相對于當前行的前2行數據,并將當前行為(wei)指定行
FETCH PRIOR FROM C ----相對于當前行的詳解前1行數據
FE(?????)TCH FI??RST FR(╯°□°)╯︵ ┻━┻OM C --剛開(kāi)始第一行的數據,并將當前行為指(′;ω;`)定行
FETCH NEXT FROM C --相對于當前行的游用法后1行數據

CLOSE C
DEALLOCATE C

結果(可以參考第一個(gè)結果分析):

具體FETCH用法:

FETCH
[ [ NEXT | PRIOR | FIRST | LAST
| ABSOLUTE { n | @nvaヾ(′▽?zhuān)??r }
| REL??ATIVE { n | @nvar }
]
FROM
]
{ { [ GLOBAL ] cursor_name(?Д?) } | @cursor_variable_name }
[ INTO @variable_name [ ,...n ] ]

Arguments??

NEXT

Returns the result row immediately following the current row and increments the current row to the row returned. If FETCH NEXT is the(′?_?`) first fetch against a cursor, it?? returns the first row in the result set. NEXT is the default cursor fetch option.

PRIOR

Returns the result row immedia(?Д?)tely preceding(?????) the current row, and decrements the current row to the row returne(°□°)d. If FETCH PRIOR is the first fetch against a cursor,?? no row is returned and the cursor is left positioned before the first row.

FIRST

Returns the firs??t row in the cursor and makes it the current row.

LAST

Returns the last row in the cursor and makes it the current row.

ABSOLUTE { n| @nvar}

If n or @nvar is positive,??? returns the row n rows from the front of the cursor and ma(′;ω;`)kes the returned row the new current row. If n or @nvar is negative, returns the row n rows before the end of the cursor and maヾ(′?`)?kes the returned row the new current row. If n or @nvar is 0, no roヽ(′ー`)ノws are returned. n must be an integer constant and @nvar must be smallint, tinyint, or int.

RELATIVE { n| @nvar}

If n or @nvar is positive, returns the row n rows beyond the?? current row and makes the return(′Д` )ed row the new current row. If n or @nvar is negative, returns the row n row??s prior to the current row and makes the retur??ned row the new current row. If n or @nvar is 0, returns the current row. If FETCH RELATIVE is specified with n or @nvar set to negative numbers or 0 on the fi??rst fetch done against a cursor, no rows are returned. n must be an integer┐(′ー`)┌ constant and @nvar must be smallint, tinyint, or int.

GLOBAL

Specifies that cursor_name refers to a global cursor.

cursor_name

Is the name of the open='open' cursor from which the fetch should?? be made. If both a global and a local cursor ex??ist with cursor_name as their name, cursor_name to the global cursor if GLOBAL is spec??ified and to the local cursor if GLOBA??L is not spec(/ω\)ified.

@cursor_variable_name

Is the name of a cursor variable referencing the open="open" cursor from which the fetch should be made.

INTO @variable_name[ ,...ヾ(′▽?zhuān)??n]

Allows data from?? the columns of a fetch to be placed into local variables. Each variable in the list, from left to right, is associated with the corresponding column in the cursor result set. The data type of each variable must either match or be a supported implicit conversion of the data type of the corresponding result set column. The number of variables must match the number of columns in the cursor select liヾ(′▽?zhuān)??st.

以上就是詳解SQL游標的用法的詳細內容,更多關(guān)于SQL游標用法的詳解資料請關(guān)注腳本之家其它相關(guān)文章!

游用法

來(lái)源:腳本之家

游用法

鏈接:https://www.jb51.net/article/188053.htm

游用法
亚洲女同成aV人片在线观看|亚洲www啪成人一区二区麻豆|亚洲国产中日韩精品综合|亚洲国产成人精品一级片|亚洲无码在线视频免费 大理市| 新源县| 蒙阴县| 南京市| 麦盖提县| 丹江口市| 昆山市| 甘肃省| 鲁山县| 东宁县| 曲麻莱县| 鹿邑县| 灵寿县| 汝南县| 定结县| 玉山县| 三穗县| 大同县| 潜山县| 长沙市| 壤塘县| 新竹市| 洪洞县| 万山特区| 庆阳市| 专栏| 台中市| 塔城市| 克拉玛依市| 临颍县| 铅山县| 兰西县| 唐海县| 和林格尔县| 江源县| 兴隆县| 泰兴市| 双江| 湛江市| 塔河县| 昂仁县| http://444 http://444 http://444 http://444 http://444 http://444