can we call a procedure from a function?
Answer Posted / abhishekjaiswal
DECLARE
FUNCTION my_func RETURN NUMBER IS
BEGIN
RETURN 2;
END my_func;
PROCEDURE my_proc IS
BEGIN
DBMS_OUTPUT.PUT_LINE(my_func + 1);
END my_proc;
BEGIN -- main
my_proc;
END; -- main
As shown above, with the function declared first you can call the function from the procedure. However, if you try something like the following (function declared before procedure, and function calls procedure):
DECLARE
FUNCTION my_func RETURN NUMBER IS
BEGIN
my_proc;
RETURN 2;
END my_func;
PROCEDURE my_proc IS
BEGIN
DBMS_OUTPUT.PUT_LINE('22');
END my_proc;
BEGIN -- main
DBMS_OUTPUT.PUT_LINE(my_func);
END; -- main
the compile will fail, because my_func cannot 'see' my_proc. To make it work you need to put in a 'prototype' declaration of my_proc, as follows:
DECLARE
PROCEDURE my_proc;
FUNCTION my_func RETURN NUMBER IS
BEGIN
my_proc;
RETURN 2;
END my_func;
PROCEDURE my_proc IS
BEGIN
DBMS_OUTPUT.PUT_LINE('22');
END my_proc;
BEGIN -- main
DBMS_OUTPUT.PUT_LINE(my_func);
END; -- main
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What does subquery mean in sql?
What is faster join or subquery?
tell me about various levels of constraint. : Sql dba
what is 'mysqlshow'? : Sql dba
Define commit?
Why we use join in sql?
How to use sql*plus built-in timers?
What are %type and %rowtype for?
How to take user input in pl sql?
How do you update f as m and m as f from the below table testtable?
What does select count (*) mean in sql?
Is sql sequential or random?
Why do we create views in sql?
Can we call stored procedure in function?
How would you convert date into julian date format?