A local module is a procedure or function that is defined in the declaration section of a PL/SQL block.
Example:
DECLARE
PROCEDURE show_date (date_in IN DATE) IS
BEGIN
DBMS_OUTPUT.PUT_LINE (TO_CHAR (date_in, 'Month DD, YYYY');
END;
BEGIN
...
END;
Note:
Local modules must be located after all of the other declaration statements in the declaration section.
we must declare our variables, cursors, exceptions, types, records, tables, and so on before we type in the
first PROCEDURE or FUNCTION keyword.
Benefits:
1.To reduce the size of the module by stripping it of repetitive code.
2.To improve the readability of your code.
Local modules can be called only from within the block in which they are defined.
Example:
Declare
my_avg_1 number;
my_avg_2 number;
my_avg_3 number;
Function Calculate_averages (n1 number,n2 number,n3 number,n4 number,n5 number)
return number
is
begin
return ((n1+n2+n3+n4+n5)/5);
end Calculate_averages;
Begin
my_avg_1 := calculate_averages(10,20,30,40,50);
my_avg_2 := calculate_averages(100,200,300,400,500);
my_avg_3 := calculate_averages(1000,2000,3000,4000,5000);
dbms_output.put_line ('my_avg_1:'|| my_avg_1);
dbms_output.put_line ('my_avg_2:'|| my_avg_2);
dbms_output.put_line ('my_avg_3:'|| my_avg_3);
END;
/
No comments:
Post a Comment