



全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Passing Large Data Structures with the NOCOPY Compiler HintSuppose a subprogram declares an IN parameter, an OUT parameter, and an IN OUT parameter. When you call the subprogram, the IN parameter is passed by reference. That is, a pointer to the IN actual parameter is passed to the corresponding formal parameter. So, both parameters reference the same memory location, which holds the value of the actual parameter.By default, the OUT and IN OUT parameters are passed by value. That is, the value of the IN OUT actual parameter is copied into the corresponding formal parameter. Then, if the subprogram exits normally, the values assigned to the OUT and IN OUT formal parameters are copied into the corresponding actual parameters.When the parameters hold large data structures such as collections, records, and instances of object types, all this copying slows down execution and uses up memory. To prevent that, you can specify the NOCOPY hint, which allows the PL/SQL compiler to pass OUT and IN OUT parameters by reference.In the following example, you ask the compiler to pass IN OUT parameter my_staff by reference instead of by value:DECLARE TYPE Staff IS VARRAY(200) OF Employee; PROCEDURE reorganize (my_staff IN OUT NOCOPY Staff) IS .Remember, NOCOPY is a hint, not a directive. So, the compiler might pass my_staff by value despite your request. Usually, however, NOCOPY succeeds. So, it can benefit any PL/SQL application that passes around large data structures.In the example below, 25000 records are loaded into a local nested table, which is passed to two local procedures that do nothing but execute NULL statements. However, a call to one procedure takes 21 seconds because of all the copying. With NOCOPY, a call to the other procedure takes much less than 1 second.SQL SET SERVEROUTPUT ONSQL GET test.sql 1 DECLARE 2 TYPE EmpTabTyp IS TABLE OF emp%ROWTYPE; 3 emp_tab EmpTabTyp := EmpTabTyp(NULL); - initialize 4 t1 NUMBER(5); 5 t2 NUMBER(5); 6 t3 NUMBER(5); 7 PROCEDURE get_time (t OUT NUMBER) IS 8 BEGIN SELECT TO_CHAR(SYSDATE,SSSSS) INTO t FROM dual; END; 9 PROCEDURE do_nothing1 (tab IN OUT EmpTabTyp) IS 10 BEGIN NULL; END; 11 PROCEDURE do_nothing2 (tab IN OUT NOCOPY EmpTabTyp) IS 12 BEGIN NULL; END; 13 BEGIN 14 SELECT * INTO emp_tab(1) FROM emp WHERE empno = 7788; 15 emp_tab.EXTEND(24999, 1); - copy element 1 into 2.25000 16 get_time(t1); 17 do_nothing1(emp_tab); - pass IN OUT parameter 18 get_time(t2); 19 do_nothing2(emp_tab); - pass IN OUT NOCOPY parameter 20 get_time(t3); 21 dbms_output.put_line(Call Duration (secs); 22 dbms_output.put_line(-); 23 dbms_output.put_line(Just IN OUT: | TO_CHAR(t2 - t1); 24 dbms_output.put_line(With NOCOPY: | TO_CHAR(t3 - t2); 25* END;SQL /Call Duration (secs)-Just IN OUT: 21With NOCOPY: 0DECLARE TYPE EmpTabTyp IS TABLE OF emp%ROWTYPE; emp_tab EmpTabTyp := EmpTabTyp(NULL); - initialize t1 NUMBER(5); t2 NUMBER(5); t3 NUMBER(5); PROCEDURE get_time (t OUT NUMBER) IS BEGIN SELECT TO_CHAR(SYSDATE,SSSSS) INTO t FROM dual; END; PROCEDURE do_nothing1 (tab IN OUT EmpTabTyp) IS BEGIN NULL; END; PROCEDURE do_nothing2 (tab IN OUT NOCOPY EmpTabTyp) IS BEGIN NULL; END;BEGIN SELECT * INTO emp_tab(1) FROM emp WHERE empno = 7788; emp_tab.EXTEND(249999, 1); - copy element 1 into 2.250000 get_time(t1); do_nothing1(emp_tab); - pass IN OUT parameter get_time(t2); do_nothing2(emp_tab); - pass IN OUT NOCOPY parameter get_time(t3); dbms_output.put_line(Call Duration (secs); dbms_output.put_line(-); dbms_output.put_line(Just IN OUT: | TO_CHAR(t2 - t1); dbms_output.put_line(With NOCOPY: | TO_CHAR(t3 - t2);END;/Call Duration (secs) -250000条记录,即25万条记录- Just IN OUT: 2With NOCOPY: 0PL/SQL 过程已成功完成。Call Duration (secs) -2500000条记录,即250万条记录-Just IN OUT: 381With NOCOPY: 0PL/SQL 过程已成功完成。The Trade-Off for Better Performance with NOCOPYNOCOPY lets you trade well-defined exception semantics for better performance. Its use affects exception handling in the following ways: Because NOCOPY is a hint, not a directive, the compiler can pass NOCOPY parameters to a subprogram by value or by reference. So, if the subprogram exits with an unhandled exception, you cannot rely on the values of the NOCOPY actual parameters. By default, if a subprogram exits with an unhandled exception, the values assigned to its OUT and IN OUT formal parameters are not copied into the corresponding actual parameters, and changes appear to roll back. However, when you specify NOCOPY, assignments to the formal parameters immediately affect the actual parameters as well. So, if the subprogram exits with an unhandled exception, the (possibly unfinished) changes are not rolled back. Currently, RPC protocol lets you pass parameters only by value. So, exception semantics can change silently when you partition applications. For example, if you move a local procedure with NOCOPY parameters to a remote site, those parameters will no longer be passed by reference. Also, the use of NOCOPY increases the likelihood of parameter aliasing. For more information, see Understanding Subprogram Parameter Aliasing.Restrictions on NOCOPYIn the following cases, the PL/SQL compiler ignores the NOCOPY hint and uses the by-value parameter-passing method (no error is generated): The actual parameter is an element of an index-by table. This restriction does not apply to entire index-by tables. The actual parameter is constrained (by scale or NOT NULL for example). This restriction does not exte
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- HSV-1-IN-3-生命科学试剂-MCE
- 2025吉林通化市公益性岗位拟聘用人员模拟试卷及答案详解(夺冠)
- Glycyl-L-alpha-amino-epsilon-pimelyl-D-alanine-CoA-Glycyl-L-alpha-amino-epsilon-pimelyl-D-alanine-coenzyme-A-生命科学试剂-MCE
- 2025广东广州市黄埔区教育局招聘事业编制教职员206人考前自测高频考点模拟试题及一套参考答案详解
- 2025年数字在线服务项目合作计划书
- 2025年温度校验仪表合作协议书
- 工程项目管理进度计划与质量控制模板
- 安全培训效果合格标准课件
- 2025年上海复旦大学附属浦东实验学校教师招聘考前自测高频考点模拟试题及答案详解参考
- 安全培训效果及小结简短课件
- 商务谈判(完整版)课件
- 小学数学教师新课标考试试题
- 小学数学北师大四年级上册五方向与位置四上《用数对确定位置》北师大版李雪梅PPT
- 步进电机控制系统课件
- 2022年混凝土预制U型槽单元工程质量评定表
- 井喷及井喷失控案例教育
- 职业发展与就业创业指导ppt课件完整版
- 挠度计算模板表格(自动版)
- 宝钢集团生产安全事故案例汇编
- 潍城区5万吨污水处理厂及配套管网建设项目环评报告书
- 为老年人更换纸尿裤评分标准
评论
0/150
提交评论