sql:oracle, CURSOR
Cursors
You use a cursor to fetch rows returned by a query. You retrieve the rows into the cursor using a
query and then fetch the rows one at a time from the cursor. You typically use the following five
steps when using a cursor:
1. Declare variables to store the column values for a row.
2. Declare the cursor, which contains a query.
3. Open the cursor.
4. Fetch the rows from the cursor one at a time and store the column values in the variables
declared in Step 1. You would then do something with those variables, such as display
them on the screen, use them in a calculation, and so on.
5. Close the cursor.
1.T-SQL用法三(游标和Fetch) http://www.cnblogs.com/McJeremy/archive/2008/09/26/1299818.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | use pubs go --1,2 declare declare @auid char (12),@aulname varchar(20),@aufname varchar(20), @st char (2),@auinfo varchar(50)<br>declare auth_cur cursor for select au_id, au_lname, au_fname, state from authors <br>--3.open open auth_cur <br>--4.fetch fetch next from auth_cur into @auid,@aulname,@aufname, @st while (@@fetch_status=0) begin print '作者编号: ' +@auid print '作者姓名: ' +@aulname+ ',' +@aufname print '所在州: ' +@st print '--------------------------' fetch next from auth_cur into @auid,@aulname,@aufname, @st end --5,6.close, deallocate close auth_cur deallocate auth_cur |
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步