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


Please Help Members By Posting Answers For Below Questions

What is sqlite format?

614


What will you get by the cursor attribute sql%found?

527


What does desc stand for?

574


Does sql view stored data?

523


Can we use having without group by in sql?

535






How to fetch alternate records from a table?

660


What is the usage of nvl function?

586


What is an emotional trigger?

505


how is myisam table stored? : Sql dba

590


Can pl sql procedure have a return statement?

536


Why do we use cursors?

499


What is the difference between distinct and unique in sql?

462


What do you think about pl/sql?

521


can a stored procedure call itself or recursive stored procedure? How much level sp nesting is possible? : Sql dba

518


Suppose a student column has two columns, name and marks. How to get name and marks of the top three students.

516