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

How to generate a salary slip like jan 1000 1000 feb 1000 2000 ... dec 1000 12000

1648


What does pragma mean?

513


Which tcp/ip port does sql server run on? How can it be changed? : Sql dba

501


How to Execute a Package in PL/SQL.?

589


What is sql injection vulnerability?

500






what is a composite primary key ? : Sql dba

585


Which nosql database is best?

519


How can you get sql*loader to commit only at the end of the load file? : aql loader

556


What is sql*loader and what is it used for?

583


What is posting?

614


What is an intersect?

657


how many tables will create when we create table, what are they? : Sql dba

549


Is a foreign key always unique?

536


What is anonymous block in sql?

640


What's the procedure?

496