zoukankan      html  css  js  c++  java
  • 游标SQL Cursor 基本用法

    http://www.cnblogs.com/Gavinzhao/archive/2010/07/14/1777644.html

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

  • 相关阅读:
    构建高性能的读服务
    Redis基础入门
    基于TCP实现简单的聊天室
    递归

    Go标准库Cond
    排序(冒泡,选择,插入,快速)
    链表
    队列
    Golang实现RPC
  • 原文地址:https://www.cnblogs.com/xyao1/p/7800705.html
Copyright © 2011-2022 走看看