This lesson demonstrates an example of how to add a function to a procedure. The following MouseOver shows how you can use a function within a procedure.
Here we create a new procedure called DO_ADDRESS. The function FORMAT_ZIP, which was demonstrated in an earlier lesson, is used within the procedure. Afterwards, we demonstrate the syntax for removing a procedure.
Now that you have seen an example of calling a function from a procedure, you could apply this knowledge to calling just about any kind of sub-program from any other.
For example, you could call a procedure from a trigger; you could create a function that calls a procedure or another function; you could call one procedure from another procedure and call a function from the called procedure; and so on.
The next lesson concludes this module.
Click the link below to modify a procedure using an evaluative simulation. Function Procedure
Question: I am working with Oracle database 10g. Is it possible to create a function inside a procedure because I do not want to use package. Answer: Yes, it is possible. In the declaration section of the procedure, you can declare and define a function. But this function wil be private to this procedure and can not be called from outside.
SQL> create or replace procedure test
3 l_dt date;
5 function dt
6 return date
9 return sysdate;
13 l_dt := dt;
14 dbms_output.put_line(to_char(l_dt, 'dd-mm-yyyy'));
SQL> exec test
PL/SQL procedure successfully completed.