How To Pass Parameters to Procedures

Q

How To Pass Parameters to Procedures? - Oracle DBA FAQ - Introduction to PL/SQL

✍: FYIcenter.com

A

Store procedures or functions can take parameters. You need to define parameters while defining the procedure, and providing values to parameters while calling the procedure. The script below shows you how to do this:

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

SQL> EXECUTE DBA_TASK('MONDAY');
Checking log files.

SQL> EXECUTE DBA_TASK('SUNDAY');
Reading some papers.

As you can see, procedures with parameters can make procedures more flexible.

2007-04-26, 4973👍, 0💬