 |
|
Oracle Tips by Burleson |
Calling Procedures from PL/SQL
If calling a procedure from SQL*Plus is easy,
calling it from PL/SQL is effortless. Simply call it in the code
section of any PL/SQL block
.
SQL> create
or replace procedure get_area
2 (n_length in number,
3 n_width in number,
4 n_area out number)
5 as
6 begin
7 n_area := n_length*n_width;
8 end get_area;
9 /
Procedure
created.
SQL> declare
2 n_area number :=0;
3 begin
4 get_area(10,20,n_area);
5 dbms_output.put_line('Area '||n_area);
6 end;
7 /
Area 200
Notice that the EXECUTE
clause is not used. That is a SQL*Plus
command and not used in
PL/SQL. Also notice that the n_area variable is not passed by
reference as in the SQL*Plus call. This is because the variable is
local where as in the SQL*Plus example, it was external to the
database.
The Return Clause with Procedures
As shown in the next section, a PL/SQL function is
required to return a value using the RETURN clause. A
procedure can also use the RETURN clause but can not return a value.
Instead, the RETURN clause terminates execution of the procedure and
processing passes back to the calling code. If the procedure was
passed OUT or INOUT variables, the
procedure will copy their values as of the RETURN clause. As with the
GOTO clause, using the RETURN clause to terminate a procedure is
considered bad programming practice and should be avoided.
The above book excerpt is from:
Easy Oracle PL/SQL Programming
Get Started
Fast with Working PL/SQL Code Examples
ISBN 0-9759135-7-3
John Garmany
http://www.rampant-books.com/book_2005_1_easy_plsql.htm
|