Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask PL-SQL Expert

Parameter Aliasing 

To optimize the subprogram call, the PL/SQL compiler can decide between the two techniques of the parameter passing. With the by-value techniques, the value of a real parameter is passed to the subprogram. With the by-reference techniques, only a pointer to the value is passed, in that case the actual and formal parameters reference the similar item.

The NOCOPY compiler hint increases the possibility of aliasing (i.e. having the two different names refer to the similar memory location). This can happen when a global variable appears as the actual parameter in a subprogram call and then is referenced within the subprogram. The result is indeterminate as it depends on the technique of parameter passing chosen by the compiler.

In the illustration below, the procedure add_entry refers to varray lexicon in two various ways: as the parameter and as a global variable. Therefore, if add_entry is called, the identifiers word_list & lexicon name the similar varray.

DECLARE

TYPE Definition IS RECORD (

word VARCHAR2(20),

meaning VARCHAR2(200));

TYPE Dictionary IS VARRAY(2000) OF Definition;

lexicon Dictionary := Dictionary();

PROCEDURE add_entry (word_list IN OUT NOCOPY Dictionary) IS

BEGIN

word_list(1).word := 'aardvark';

lexicon(1).word := 'aardwolf';

END;

BEGIN

lexicon.EXTEND;

add_entry(lexicon);

DBMS_OUTPUT.PUT_LINE(lexicon(1).word);

-- prints 'aardvark' if parameter was passed by value

-- prints 'aardwolf' if parameter was passed by reference

END;

The output depends on the technique of parameter passing chosen by the compiler. If the compiler chooses the by-value technique, word_list and lexicon are individual copies of the similar varray. Therefore, changing one does not affect the other. Whereas, if the compiler chooses the by-reference technique, word_list and lexicon are merely different names for the similar varray. (And Hence, the word "aliasing.")

The Aliasing can also occur if similar actual parameter appears more than once in a subprogram call. In the illustration below, n2 is an IN OUT parameter, therefore the value of the actual parameter is not updated till the procedure exits. This is why the first PUT_LINE prints 10 (the initial value of n) and the third PUT_LINE prints 20.

Though, n3 is a NOCOPY parameter, for this reason the value of the actual parameter is updated instantly. That is why the second PUT_LINE prints 30.

DECLARE

n NUMBER := 10;

PROCEDURE do_something (

n1 IN NUMBER,

n2 IN OUT NUMBER,

n3 IN OUT NOCOPY NUMBER) IS

BEGIN

n2 := 20;

DBMS_OUTPUT.PUT_LINE(n1); -- prints 10

n3 := 30;

DBMS_OUTPUT.PUT_LINE(n1); -- prints 30

END;

BEGIN

do_something(n, n, n);

DBMS_OUTPUT.PUT_LINE(n); -- prints 20

END;

As they are pointers, the cursor variables also increase the possibility of the aliasing. Consider the illustration below. Later the assignment, emp_cv2 is an alias of the emp_cv1 as both points to the similar query work region. Therefore, both can alter its position. So are why the first fetch from emp_cv2 fetches the third row and why the second fetch from emp_cv2 fails after you close emp_cv1.

PROCEDURE get_emp_data (

emp_cv1 IN OUT EmpCurTyp,

emp_cv2 IN OUT EmpCurTyp) IS

emp_rec emp%ROWTYPE;

BEGIN

OPEN emp_cv1 FOR SELECT * FROM emp;

emp_cv2 := emp_cv1;

FETCH emp_cv1 INTO emp_rec; -- fetches first row

FETCH emp_cv1 INTO emp_rec; -- fetches second row

FETCH emp_cv2 INTO emp_rec; -- fetches third row

CLOSE emp_cv1;

FETCH emp_cv2 INTO emp_rec; -- raises INVALID_CURSOR

...

END;

PL-SQL, Programming

  • Category:- PL-SQL
  • Reference No.:- M9510487

Have any Question?


Related Questions in PL-SQL

For this assignment you will be provided a database backup

For this assignment, you will be provided a database backup for a database called FinanceDB. You will have to restore this backup to your own version of SQL Server. All of the questions in this assignment relate to the F ...

Complete the following tasksin microsoft access create the

Complete the following tasks: In Microsoft Access, create the database and tables that you identified in W3 Assignment 2. In Microsoft Word, write the SQL statements to create the database and tables. Write SQL statement ...

Assignment - queries functions and triggersaimthe aims of

Assignment - Queries, Functions and Triggers Aim The aims of this assignment are to: formulate SQL queries; populate an RDBMS with a real dataset, and analyse the data; design test data for testing SQL queries; create SQ ...

Purpose of the assessment with ulo mapping the purpose of

Purpose of the assessment (with ULO Mapping) The purpose of this assignment is to develop skills in managing data in databases and to gain understanding of data model development and implementation using a commercially a ...

Continuing the project you have worked on in weeks 1-4 in

Continuing the project you have worked on in Weeks 1-4, in this final week, complete the following tasks: Refine your database and SQL statements by incorporating your instructor's feedback. Verify that the database comp ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As