The following article mainly describes the SQL Server cursor instance, if you encounter a SQL Server cursor instance in the actual operation, but you do not know how to apply correctly to it, then the following article to you must be a mentor, hope will give you some help in this respect.
SQL Server Cursor instance:
- Declare Mycusror Cursor Scroll
- For a Select * from Master_goods ORDER by Goodsid
- Open MyCursor
- Fetch Next from MyCursor
- Into @GoodsCode, @GoodsName
- while (@ @Fetch_Status = 0)
- Begin
- Begin
- Select @GoodsCode = Convert (Char (), @GoodsCode)
- Select @GoodsName = Convert (Char (), @GoodsName)
- PRINT @GoodsCode + ': ' + @GoodsName
- End
- Fetch Next from MyCursor
- Into @GoodsCode, @GoodsName
- End
- Close MyCursor
- Deallocate mycursor
The data method for modifying the current cursor is as follows:
- UpDate master_goods Set goodsname = ' php100 ' Where current of MyCursor
The method for deleting the current cursor row data is as follows:
- Delete from Master_goods Where Current of MyCursor
The Select @ @CURSOR_ROWS can get the number of rows of data that exist in the current cursor. Note: This variable is a global variable on a connection and therefore corresponds to the last open cursor only.
Open cursor
Global cursors: Open global MyCursor
Local cursors: Open mycursor
The above is a description of the SQL Server cursor instance, and hope you get something.