What is nocopy in plsql?



What is nocopy in plsql?..

Answer / anks

Prior to Oracle 8i releases, the IN OUT parameters in
PL/SQL routines were passed using the copy-in and copy-out
semantics (call by value).

For example:


create or replace procedure cpy_chk
(pi_val in varchar2,
po_dat out date,
pio_status in out varchar2) is
begin
po_dat := sysdate;
pio_status := pio_status || 'amar is testing';
end;
When the above code is executed, Oracle will copy the value
being passed to parameters PO_DAT and PIO_STATUS in a
separate buffer for the routine. On completion of the
routine, Oracle will copy the value being held in the
PO_DAT and PIO_STATUS parameters back to the original
variable. This results in multiple buffers being opened in
memory and the overhead of copying data back and forth.
This can be huge in terms of CPU and Memory overhead if the
parameter is meant for large strings or collection objects.
The IN parameter is passed by reference; that is, a pointer
to the actual IN parameter is passed to the corresponding
formal parameter. So, both parameters refer to the same
memory location and no copying overhead is involved.
However, the OUT and IN OUT parameters are passed by value.

To get around this, package variables were being used to
pass values around. Though serviceable as an alternative to
prevent multiple buffers and copy overhead, it resulted in
higher maintenance cost.

From Oracle 8i onwards, the NOCOPY parameter hint has been
introduced for OUT and IN OUT parameters. Using this hint
tells Oracle to make a call by reference. Use this hint
when there is no need to preserve the original value (in
case the called routine raises an exception). Oracle's
internal benchmark testing shows improvements of 30% to
200% for PL/SQL tables being passed as parameters. NOCOPY
is the ideal hint for OUT and IN OUT parameters when the
original value is not to be preserved (as is generally the
case).

Here's an example:


create or replace procedure cpy_chk
(pi_val in varchar2,
po_dat out nocopy date,
pio_status in out nocopy varchar2) is
begin
po_dat := sysdate;
pio_status := pio_status || 'amar is testing';
end;


Drawbacks
NOCOPY is a hint and Oracle does not guarantee a parameter
will be passed by reference when explicitly mentioned. Here
are some places where this is not possible:

When the call is a remote procedure call
When the actual parameter being passed is an expression
When there is an implicit conversion involved
There may be other situations where Oracle may decide a
call by value over a call by reference. Since this is not
clearly specified, it is advisable not to build any process
logic on this feature when exceptions being raised in the
called routine are being trapped in the calling routine.

Is This Answer Correct ?    2 Yes 0 No

Post New Answer

More Programming Languages AllOther Interview Questions

Write a shell program to test whether a given year is leap year or not ?

0 Answers   Patni,


Can anyone provide as400 training material or any institute in bangalore for as400 training

10 Answers  


Write a program to show polymorphism.

0 Answers   Genpact,


For C sharp,At the time of software is implemented at client site, is it required that client machine have C sharp(Microsoft Visual Basic) setup?

1 Answers   Honeywell,


what is the work of 1tier,2tier,&ntier? Plz Explain it!

0 Answers  






How to change the color of a cell or a row in a datagrid on mouse hover using javascript/.net

0 Answers   Tesco, Wipro,


1. Write a program to create a sentence at runtime and count number of vowels in it ? 2. Write a program to get a string and to convert the 1st letter of it to uppercase ?

0 Answers   HTC,


what is the pl/sql block size in oracle 10g and 11g?

0 Answers  


a characteristic of a multiprogramming is? a.simultaneous exe of pgm instr 4m 2 appli b.concurrent processing of 2 r more prgms c.multiple cpu s d.all the abov

0 Answers   TCS,


hai i am mca 2009 fresher.please tell me which certification helps me to get an IT job faster which institute is good in hyderabad.please mail me to prasanna.1856@rediff.com

0 Answers  


1Q) your current CTC (current taking currency)? 2Q) Your take home salary?(Monthly Drawing amount, According to your payslips/bank statement) 3Q) Your Expected CTC? 4Q) Your home take salary?

1 Answers  


what is the difference between Windows application and Unix application?

0 Answers   Satyam,


Categories