好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > 詳解SQL游標的用法

詳解SQL游標的用法

熱門標簽:百度地圖標注不同路線 優質地圖標注 奧威地圖標注多個地方 怎樣在地圖上標注路線圖標 智能語音外呼系統選哪家 外呼系統電銷專用 京華物流公司地圖標注 千呼電銷機器人價格 武漢長沙外呼系統方法和技巧

類型:

       1.普通游標   只有NEXT操作

       2.滾動游標 有多種操作

1.普通游標

DECLARE @username varchar(20),@UserId varchar(100)
DECLARE cursor_name CURSOR FOR --定義游標
  SELECT TOP 10 UserId,UserName FROM UserInfo
  ORDER BY UserId DESC
OPEN cursor_name --打開游標
FETCH NEXT FROM cursor_name INTO @UserId,@username --抓取下一行游標數據
WHILE @@FETCH_STATUS = 0
  BEGIN
    PRINT '用戶ID:'+@UserId+'      '+'用戶名:'+@username
    FETCH NEXT FROM cursor_name INTO @UserId,@username
  END
CLOSE cursor_name --關閉游標
DEALLOCATE cursor_name --釋放游標

結果:

用戶ID:zhizhi            用戶名:鄧鴻芝
用戶ID:yuyu            用戶名:魏雨
用戶ID:yujie            用戶名:李玉杰
用戶ID:yuanyuan            用戶名:王夢緣
用戶ID:YOUYOU            用戶名:lisi
用戶ID:yiyiren            用戶名:任毅
用戶ID:yanbo            用戶名:王艷波
用戶ID:xuxu            用戶名:陳佳緒
用戶ID:xiangxiang            用戶名:李慶祥
用戶ID:wenwen            用戶名:魏文文

2.滾動游標

--帶SCROLL選項的游標
SET NOCOUNT ON
DECLARE C SCROLL CURSOR FOR --SCORLL 后,有了更多的游標操作(滾動游標)
  SELECT TOP 10 UserId,UserName FROM UserInfo
  ORDER BY UserId DESC
OPEN C 
FETCH LAST FROM C  --最后一行的數據,并將當前行為指定行
FETCH ABSOLUTE 4 FROM C --從第一行開始的第4行數據,并將當前行為指定行 這里的n可正可負,n>0 往下翻,n0 往上翻
FETCH RELATIVE 3 FROM C --相對于當前行的后3行數據,并將當前行為指定行 這里的n可正可負
FETCH RELATIVE -2 FROM C --相對于當前行的前2行數據,并將當前行為指定行
FETCH PRIOR FROM C  ----相對于當前行的前1行數據
FETCH FIRST FROM C  --剛開始第一行的數據,并將當前行為指定行
FETCH NEXT FROM C  --相對于當前行的后1行數據

CLOSE C
DEALLOCATE C

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

具體FETCH用法:

FETCH  
     [ [ NEXT | PRIOR | FIRST | LAST  
          | ABSOLUTE { n | @nvar }  
          | RELATIVE { 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 immediately preceding the current row, and decrements the current row to the row returned. 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 first 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 makes 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 makes the returned row the new current row. If n or @nvar is 0, no rows 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 returned row the new current row. If n or @nvar is negative, returns the row n rows prior to the current row and makes the returned 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 first 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 cursor from which the fetch should be made. If both a global and a local cursor exist with cursor_name as their name, cursor_name to the global cursor if GLOBAL is specified and to the local cursor if GLOBAL is not specified.

@cursor_variable_name

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

INTO @variable_name[ ,...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 list.

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

您可能感興趣的文章:
  • MySQL游標概念與用法詳解
  • mysql的存儲過程、游標 、事務實例詳解
  • Python操作SQLite數據庫的方法詳解【導入,創建,游標,增刪改查等】
  • MySQL使用游標批量處理進行表操作
  • Sql存儲過程游標循環的用法及sql如何使用cursor寫一個簡單的循環
  • Mysql存儲過程循環內嵌套使用游標示例代碼
  • MySql游標的使用實例

標簽:七臺河 防疫戰設 來賓 天水 益陽 威海 宿州 銅仁

巨人網絡通訊聲明:本文標題《詳解SQL游標的用法》,本文關鍵詞  詳解,SQL,游,標的,用法,詳解,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《詳解SQL游標的用法》相關的同類信息!
  • 本頁收集關于詳解SQL游標的用法的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 女人被男人到爽视频 | 精品久久洲久久久久护士| 国产欧美亚洲| 亚洲动漫精品| 老师办公室扒开奶罩揉吮奶头漫画| 国产精品秘?八口麻豆| 黄频网址| 三级做a全过程在线观看| 韩国黄色小说| 仙子无力玉腿呻吟迎合| 欧美一级婬片a毛片无码| 国产9Ⅰ露脸色情按摩免费视频| 全球AV集中精品导航福利| 男男gaygays网站欧洲| 中文字幕精品一区影音先锋| 成人综合在线视频免费观看| 8x8x8x8x.io成人网站| 欧美AV无码久久一区二区天堂| 日本流氓片| 91亚洲国产| 一区二区三区四区电影| 搞黄网址| 亚洲男人天堂av| 亚洲区欧美区小说区图片区| 农村国产妇女精品一吃春药的效果| 漂漂电影网| 黄色小小说| 他舌头伸进她腿间花缝| 黑料吃瓜网曝一区二区| 免费国产成人高清在线观看麻豆| 好涨太深太大了受不了| 精人妻无码一区二区三区苍井空| 艹艹逼| 韩国三级hd高清在线观看| 让女人爽爆的囗交方式| 第一次跟女婿做过爱| 国产精品30p| ▓▓草莓视频▓无码免费| 武则天成人版1995未删减版| 免费日本在线视频| 国产色妇|