Differences between "in"/"out" and "nocopy"
2013-04-02 10:10
309 查看
By default, PL/SQL passes
to a temporary variable, which holds the value of the parameter during subprogram execution. If the subprogram is exited normally, then PL/SQL copies the value of the temporary variable to the corresponding actual parameter. If the subprogram is exited with
an unhandled exception, then PL/SQL does not change the value of the actual parameter.
When
memory use—especially for an instance of an ADT.
For each invocation of an ADT method, PL/SQL copies every attribute of the ADT. If the method is exited normally, then PL/SQL applies any changes that the method made to the attributes. If the method is exited with an unhandled exception, then PL/SQL does not
change the attributes.
Above are the describe in Oracle standard document. Now we use the below code to check this points:
Output:
This feature is more like the differences between pass a variable by reference and by value in C.
The "nocopy" parameters use less memory and not need to copy the values when invoked, which is useful for performance tuning.
OUTand
IN
OUTsubprogram parameters by value. Before running the subprogram, PL/SQL copies each
OUTand
IN
OUTparameter
to a temporary variable, which holds the value of the parameter during subprogram execution. If the subprogram is exited normally, then PL/SQL copies the value of the temporary variable to the corresponding actual parameter. If the subprogram is exited with
an unhandled exception, then PL/SQL does not change the value of the actual parameter.
When
OUTor
IN
OUTparameters represent large data structures such as collections, records, and instances of ADTs, copying them slows execution and increases
memory use—especially for an instance of an ADT.
For each invocation of an ADT method, PL/SQL copies every attribute of the ADT. If the method is exited normally, then PL/SQL applies any changes that the method made to the attributes. If the method is exited with an unhandled exception, then PL/SQL does not
change the attributes.
Above are the describe in Oracle standard document. Now we use the below code to check this points:
declare v_value1 number; procedure add1(p_v1 in out number) as v_t number := 1; begin p_v1 := p_v1 + 1; v_t := v_t / 0;--throw out an exception end; procedure add2(p_v1 in out nocopy number) as v_t number := 1; begin p_v1 := p_v1 + 1; v_t := v_t / 0;--throw out an exception end; begin v_value1 := 1; dbms_output.put_line('check "in"/"out": ' || v_value1); begin add2(v_value1); dbms_output.put_line(v_value1); exception when others then dbms_output.put_line('error:' || v_value1); end; v_value1 := 1; dbms_output.put_line('check "nocopy": ' || v_value1); begin add1(v_value1); dbms_output.put_line(v_value1); exception when others then dbms_output.put_line('error:' || v_value1); end; end;
Output:
check "in"/"out": 1 error:2 check "nocopy": 1 error:1
This feature is more like the differences between pass a variable by reference and by value in C.
The "nocopy" parameters use less memory and not need to copy the values when invoked, which is useful for performance tuning.
相关文章推荐
- what is the difference between "isempty"and "isnull"in the qt bool QString::isEmpty () const Retur.
- what is the difference between definition and declaration in c
- Difference between Override and Reintroduce in Delphi
- the difference between final and static in java
- Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Latin1_General_CI_AS" in the equal to
- Difference between <? super T> and <? extends T> in Java
- Difference between Set, List and Map in Java - Interview question
- Difference between Truncate and Delete command in SQL - Interview Questions with Example
- The difference between iostream and stdio in MPI
- Difference between save vs persist and saveOrUpdate in Hibernate
- Difference between JOIN and JOIN FETCH in JPA
- Difference between Abstract Class and Interface in Java
- Difference between ArrayList and LinkedList in Java
- Oracle 子程序参数模式,IN,OUT,NOCOPY
- The difference between "malloc" and "new"
- difference between Abstract class and interface in java
- Difference between px, dp, dip and sp in Android?
- Difference between HashMap, LinkedHashMap and TreeMap in Java
- Java - Difference between Wait and Sleep , Yield in Java