• 游标使用


    使用游标例

    --table1结构如下
    id    int
    name  varchar(50)
    declare @id int
    declare @name varchar(50)
    declare cursor1 cursor for         --定义游标cursor1
    select * from table1               --使用游标的对象(跟据需要填入select文)
    open cursor1                       --打开游标
    fetch next from cursor1 into @id,@name  --将游标向下移1行,获取的数据放入之前定义的变量@id,@name中
    while @@fetch_status=0           --判断是否成功获取数据
    begin
    update table1 set name=name+'1'
    where id=@id                           --进行相应处理(跟据需要填入SQL文)
    fetch next from cursor1 into @id,@name  --将游标向下移1行
    end
    close cursor1                   --关闭游标
    deallocate cursor1

    优化

    --标准游标
    declare my_cursor cursor
    for
    select * from s_yhb
    --只读游标
    declare my_cursor cursor
    for
    select * from s_yhb
    for read only
    --更新游标
    declare my_cursor cursor
    for
    select * from s_yhb
    for update
  • 相关阅读:
    运算符优先级口诀
    [转] 从最大似然到EM算法浅解
    推荐系统实践整体化总结
    Python-函数
    Python-dict/set
    Python-条件、循环、
    Python-list and tuple
    优先级顺序表
    8.1python类型注解
    9.redis-CacheCloud
  • 原文地址:https://www.cnblogs.com/bit-by-bit/p/3915225.html
Copyright © 2020-2023  润新知