- 1、本文档共27页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
存储过程,函数,游标(Stored procedures, functions, cursors)
存储过程,函数,游标(Stored procedures, functions, cursors)
A, the cursor
The cursor is a PL/SQL control structure that can be explicitly controlled for the processing of SQL statements to facilitate the processing of the data of the table.
Ps. When the amount of data in the table is large, it is not recommended to use cursors (inefficient and resource-consuming), but it can be flexible with the data method.
The cursor is a recorded pointer, which is fed back to the record of the table by using the cursor to update or delete the activity set.
Cursor properties: % FOUND, % NOTFOUND, % ROWCOUNT, % ISOPEN
1. Explicit cursors
An explicit cursor is a cursor that is explicitly declared by the user. Depending on the query defined in the cursor, the returned row set can contain zero or more rows, which are called activity sets. The cursor will point to the activity concentration.
Explicit cursor manipulation: declare, open, retrieve records from cursor, and close.
The SET SERVEROUTPUT ON.
DECLARE
CURSOR cur IS
SELECT * FROM books.
Myrecord books % ROWTYPE;
The BEGIN
The OPEN cur;
LOOP
The FETCH cur INTO books;
EXIT the WHEN cur % NOTFOUND;
Dbms_outout.put_line (book.id | | | | books.
END LOOP;
The CLOSE cur;
The END;
1.1. Explicit cursor with parameters: parameters need not specify length or precision.
1.2. FOR circular cursor: use traversal mode to open, extract and close cursors automatically. (can you use % ROWCOUNT to get the number of rows extracted from the cursor?)
DECLARE
/ * define the parameter cursor * /
CURSOR cur_para varchar2 (id) IS
SELECT books_name FROM books WHERE books_id = id;
BGEIN
/ * call the parameter cursor and handle * / with a FOR loop
FOR cur IN cur_para ( 0001 ) LOOP
DBMS_OUTPUT. PUT_LINE (cur. Books_id | | | | cur. Books_id);
END LOOP;
The END;
1.3, use the display cursor to delete or update the record
Definition: use SELECT... FOR UPDATE statement to indicate the lock of things;
When executed: use the WHERE CURRENT OF curXXX clause to specify the cursor
您可能关注的文档
- 员工手册(The employee handbook).doc
- 品牌卖场--经销商的创新突围(Brand store - dealer innovation breakout).doc
- 品牌塑造的5A体系(Brand building 5A system).doc
- 品牌形象塑造的途径(The way that brand image is shaped).doc
- 哈利波特3游戏攻略(Harry potter 3 game strategy).doc
- 品质英语2(Quality English 2).doc
- 哈大齐工业走廊大庆区域发展规划(Regional development planning of daqing industrial corridor).doc
- 哈尔滨工业大学IP段分布(Distribution of IP section of Harbin institute of technology).doc
- 哈工大附近的公交车线路(一区和二区)(Bus routes near Harbin institute of technology (district 1 and 2)).doc
- 哈尔滨桥塌(Harbin bridge collapse).doc
- 专题02+时事热点(精讲课件)2025年中考地理二轮复习讲练测(安徽专用).pptx
- 专题10+经济建设 2025年中考道德与法治二轮复习讲练测(广东专用).pptx
- 专题02+西游记【名著概览】+-+2025年中考语文必读名著演练.pptx
- 专题七+认识国家(课件)-【省心备考】2025年中考地理一轮复习优质课件.pptx
- 第22课《礼记》二则——《大道之行也》(课件)-2024-2025学年八年级语文下册同步备课精品资源.pptx
- 跨学科实践15:制作“龙骨水车”(课件)-2024-2025学年八年级物理下学期项目化课程案例.pptx
- 第13课_辽宋夏金元时期的对外交流(课件)2024-2025学年七年级历史下册同步教学课件.pptx
- 选择题专项讲解——综合类(课件)2025年初中道德与法治中考选择题练习.pptx
- 第21课《庄子》二则——《北冥有鱼》(课件)-2024-2025学年八年级语文下册同步备课精品资源.pptx
- 7.3+感受澳大利亚(第二课时)-2025学年七年级地理下册同步精品课堂(晋教版2024).pptx
文档评论(0)