CALL BY REFERENCE AND CALL
BY VALUE
Ø In parameters by default call by reference where as out and in
out call by value.
Ø When parameter passed by
reference, a pointer to the actual parameter is passed to the corresponding
formal parameter.
Ø When parameter passed by
value it copies the value of the actual parameter to the formal parameter.
Ø Call by reference is
faster than the call by value because it avoids the copying.
SUBPROGRAMS OVERLOADING
Ø Possible with different
number of parameters.
Ø Possible with different
types of data.
Ø Possible with same type
with objects.
Ø Can not be possible with
different types of modes.
Ø We can overload local
subprograms also.
Ex:
SQL> create or replace type t1
as object(a number);/
SQL> create or replace type t1
as object(a number);/
DECLARE
i t1 := t1(5);
j t2 := t2(5);
PROCEDURE P(m t1) IS
BEGIN
dbms_output.put_line('a = ' || m.a);
END P;
PROCEDURE P(n t2) IS
BEGIN
dbms_output.put_line('b = ' || n.b);
END P;
PROCEDURE PRODUCT(a number,b number) IS
BEGIN
dbms_output.put_line('Product of a,b =
' || a * b);
END PRODUCT;
PROCEDURE PRODUCT(a number,b number,c
number) IS
BEGIN
dbms_output.put_line('Product of a,b =
' || a * b * c);
END PRODUCT;
BEGIN
p(i);
p(j);
product(4,5);
product(4,5,6);
END;
Output:
a = 5
b = 5
Product of a,b
= 20
Product of a,b
= 120
BENEFITS OF OVERLOADING
Ø Supporting many data
combinations
Ø Fitting the program to the
user.
RESTRICTIONS ON
OVERLOADING
Ø Overloaded programs with
parameter lists that differ only by name must be called using named notation.
Ø The parameter list of
overloaded programs must differ by more than parameter mode.
Ø All of the overloaded
programs must be defined within the same PL/SQL scope or block.
Ø Overloaded functions must
differ by more than their return type.
No comments:
Post a Comment