Cursor SQL cursor BASIC usage

Source: Internet
Author: User

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

1The Table1 structure is as follows
2IdInt
3Namevarchar(50)
4
5Declare@idInt
6Declare@namevarchar(50)
7DeclareCursor1CursorFor--Defining Cursors Cursor1
8Select*FromTable1--Objects using cursors (fill in select text as required)
9OpenCursor1--Open cursor
10
11FetchNextFromCursor1Into@id,@name--Move the cursor down by 1 rows to get the data into the previously defined variable @id, @name
12
13While@ @fetch_status=0--Determine if the data was successfully obtained
14Begin
15UpdateTable1SetName=Name+‘1‘
16whereId=@id --Handle it accordingly (fill in the SQL text as needed)
17
18FetchNextFromCursor1Into@id,@name  -- Move the cursor down 1 rows Span style= "COLOR: #008080" >
19 end
20 
21 close cursor1                    -- close cursor
22 deallocate cursor1

Cursor SQL cursor BASIC usage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.