Oracle PL/SQL之IN OUT NOCOPY
2011-06-24 13:59
489 查看
Suppose a subprogram declares an
Test Code:
Output:
Ref:
http://download.oracle.com/docs/cd/B10500_01/appdev.920/a96624/08_subs.htm#12813
INparameter, an
OUTparameter, and an
IN
OUTparameter. When you call the subprogram, the
INparameter is passed by reference. That is, a pointer to the
INactual 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
OUTand
IN
OUTparameters are passed by value. That is, the value of the
IN
OUTactual parameter is copied into the corresponding formal parameter. Then, if the subprogram exits normally, the values assigned to the
OUTand
IN
OUTformal parameters are copied into the corresponding actual parameters. 当我们声明一个参数是IN类型时,进行传参是将传给该参数一个实参的指针;当我们声明一个参数是OUT或者IN OUT类型时,进行传参是将传给该参数一个实参的拷贝;只有当程序正常结束时,赋给OUT或者IN OUT类型参数的值才会返回(除非使用了NOCOPY)。将NOCOPY应用在传递数据量很大的参数(such as collections, records, and instances of object types)时,可起到优化性能的作用。当参数是OUT或者IN OUT类型时:没有NOCOPY=按值传递(ByVal);加上NOCOPY=按引用传递(ByRef)。
Test Code:
DECLARE l_1 NUMBER := 10; l_2 NUMBER := 20; l_3 NUMBER := 30; PROCEDURE test_out ( p1 IN NUMBER ,x1 IN OUT NUMBER ,x2 IN OUT NOCOPY NUMBER ) IS BEGIN x1 := p1; dbms_output.put_line('inside test_out, x1=' || x1); x2 := p1; dbms_output.put_line('inside test_out, x2=' || x2); raise_application_error(-20001, 'test NOCOPY'); END; BEGIN dbms_output.put_line('before, l_1=' || l_1 || ', l_2=' || l_2 || ', l_3=' || l_3); BEGIN --the OUT parameter has no value at all until the program terminates successfully, --unless you have requested use of the NOCOPY hint test_out(l_1, l_2, l_3); EXCEPTION WHEN OTHERS THEN dbms_output.put_line('SQLCODE => ' || SQLCODE || ', SQLERRM => ' || SQLERRM); END; dbms_output.put_line('after, l_1=' || l_1 || ', l_2=' || l_2 || ', l_3=' || l_3); END;
Output:
before, l_1=10, l_2=20, l_3=30 inside test_out, x1=10 inside test_out, x2=10 SQLCODE => -20001, SQLERRM => ORA-20001: test NOCOPY after, l_1=10, l_2=20, l_3=10
Ref:
http://download.oracle.com/docs/cd/B10500_01/appdev.920/a96624/08_subs.htm#12813
相关文章推荐
- Oracle PL/SQL之IN OUT NOCOPY
- Oracle PL/SQL之IN OUT NOCOPY
- Oracle 子程序参数模式,IN,OUT,NOCOPY
- 使用 Oracle PL/SQL NOCOPY 提示
- Differences between "in"/"out" and "nocopy"
- Learn How To Attach PL/SQL Library In Oracle Forms
- Enable trace 10046 in Oracle PL/SQL
- PL/SQL Nocopy
- [Oracle Misc] Varchar2 in SQL and PL/SQL, etc
- Oracle: import tables use .dmp file in PL/SQL Developer
- Just another way of debug logging in Oracle PL/SQL
- [bbk4979]第06集 - Chapter 04- Interacting with Oracle Database Server:SQL Statements in PL/SQL Programs(01)
- IN OUT NOCOPY 分析
- PL/SQL Enhancements in Oracle Database 10g
- Declare Variables, Constants and Types in Oracle PL/SQL
- oracle bug? ORA-07445 ,pl/sql for in()
- ORACLE HANDBOOK系列之五:PL/SQL中的集合类型(Collections in PL/SQL)
- 以传值和传引用的方式传递参数 IN OUT NOCOPY
- 优化PL/SQL过程调用,使用NOCOPY提示
- IN OUT NOCOPY