数据库笔记 6

7.2

/*创建游标testCursorA,把testCursorA看成存放游标的容器,查询网站职员表的游标记录放入testCursorA,约束为制度游标*/

declare testCursorA cursor for

select *from AddressInfos

for read only/*当前为只读游标;去掉for read only,是标准游标;for update,是更新游标*/

 

/*打开游标*/

open testCursorA

 

/*使用游标,从testCursorA依次拿出放在testCursorA里面的游标*/

fetch nextfrom testCursorA

 

 

7.3游标定义格式

declare 游标名称cursor

[Local|Global]//游标的作用范围:局部|全局

[Forward_only|Scroll]//只进游标(从前往后走)|任意滚动

[Stattic|Keyset|Dynamic|Fast_froward]

[Reae Only|Scroll_Locks|Optimistic]

[Type_warning]

for

...Sql语句...

for [read only|update]

 

 

7.4

/*创建任意滚动游标*/

declare testCursorA cursor scroll for

select *from 网站职员表

 

/*调用查询下一个游标*/

fetch nextfrom testCursorA

 

/*调用查询第一个游标*/

fetch firstfrom testCursorA

 

/*调用查询最后一个游标*/

fetch lastfrom testCursorA

 

 

7.5

/*创建可滚动游标*/

declare testCursorB cursorscroll for

select *from AddressInfos

 

/*调用游标,从前往后获取游标记录*/

fetch priorfrom testCursorB

 

 

7.07

/*创建游标*/

declaretestCursorA cursor scrollfor

select *from dbo.第二网站职员表

 

/*打开游标*/

opentestCursorA

 

/*执行*/

fetch absolutefromtestCursorA

 

/*relative把游标向前或者向后移动一个位置;relative -1把游标向前移动一个位置;relative 1把游标向后移动一个位置*/

fetch relative-1 from testCursorA

 

7.08

declare@testvar1 int,@testVar2varchar(100),@testVar3int,@testVar4 varchar(100),@testVar5money

fetch relative-2 from testCursorAinto@testVar1,@testVar2,@testVar3,@testVar4,@testVar5

 

 

7.09

/*关闭游标*/

closetestCursorA

 

/*释放游标*/

deallocatetestCursorA

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值