Home >> FAQs/Tutorials >> Oracle Tutorials

Oracle Tutorials - Define a Sub Procedure

By: FYIcenter.com

(Continued from previous topic...)

How To Define a Sub Procedure?

A sub procedure is a named procedure defined and used inside another procedure or function. You need to define a sub procedure in the declaration part of the enclosing procedure or function. Sub procedure definition starts with the PROCEDURE key word. Here is a sample script showing you how to define and use a sub procedure:

SQL> CREATE OR REPLACE PROCEDURE HR.DBA_WEEK AS          
  2    PROCEDURE DBA_TASK (day VARCHAR2) AS              
  3    BEGIN
  4      IF day = 'MONDAY' THEN           
  5        DBMS_OUTPUT.PUT_LINE('Checking log files.');  
  6      ELSIF day = 'FRIDAY' THEN        
  7        DBMS_OUTPUT.PUT_LINE('Rebuild indexes.');     
  8      ELSE              
  9        DBMS_OUTPUT.PUT_LINE('Reading some papers.'); 
 10      END IF;           
 11    END;
 12  BEGIN 
 13    DBA_TASK('MONDAY');
 14    DBA_TASK('TUESDAY');              
 15  END;  
 16  /
 
SQL> EXECUTE DBA_WEEK;
Checking log files.
Reading some papers.

(Continued on next topic...)

  1. What Is a Procedure?
  2. What Is a Function?
  3. How To Define an Anonymous Procedure without Variables?
  4. How To Define an Anonymous Procedure with Variables?
  5. How To Create a Stored Procedure?
  6. How To Execute a Stored Procedure?
  7. How To Drop a Stored Procedure?
  8. How To Pass Parameters to Procedures?
  9. How To Create a Stored Function?
  10. How To Call a Stored Function?
  11. How To Drop a Stored Function?
  12. How To Call a Stored Function with Parameters?
  13. How To Define a Sub Procedure?
  14. How To Call a Sub Procedure?
  15. How To Define a Sub Function?
  16. Can Sub Procedure/Function Be Called Recursively?
  17. What Happens If Recursive Calls Get Out of Control?
  18. What Is the Order of Defining Local Variables and Sub Procedures/Functions?
  19. What Is the Difference between Formal Parameters and Actual Parameters?
  20. What Are the Parameter Modes Supported by PL/SQL?
  21. How To Use "IN" Parameter Properly?
  22. How To Use "OUT" Parameter Properly?
  23. How To Use "IN OUT" Parameter Properly?
  24. How To Define Default Values for Formal Parameters?
  25. What Are Named Parameters?
  26. What Is the Scope of a Local Variable?

Oracle Tutorials:

More...


Other Tutorials/FAQs:

More...


Related Resources:

More...


Selected Jobs:

More...