Professional Documents
Culture Documents
(i).It is a named PL/SQL sub programs. It is compiled and stored in database for
repeated execution.
(ii).It can accept an argument/parameter and can return a value. Procedure performs
an action.
(iii).It is a schema object. It improves the performance of an application by
reducing network traffic.
(iv).If procedure is created outside the package then it is called as stored or
standalone subprograms and if is created in package then it is called packaged
subprogram.
SYNTAX:
create or replace procedure procedure_name
as
declarative statements
begin
executable statements
exception
error handling statements
end;
IN Parameter:
It is used to passing Input value to the sub program.
It is read only access.
OUT Parameter:
It is used to get output value from the procedure.
It has read / write access.
IN OUT Parameter:
It can accept both input values and return output values.
It passes an initial value to a procedure and return an updated value to the
calling code.
BEGIN
P1;
END;
EXEC P1;
DESCRIBE P1;
DESC P1;
DROP PROCEDURE P1;
DECLARE
X VARCHAR2(30);
BEGIN
P1(102,X);
END;
BEGIN
P1;
END;
BEGIN
P1(114);
END;
EXEC P1(120);
DECLARE
X NUMBER := 160;
Y VARCHAR2(30);
BEGIN
P1(X,Y);
DBMS_OUTPUT.PUT_LINE(Y);
END;
CREATE OR REPLACE PROCEDURE P1(ID NUMBER,NAME OUT VARCHAR2,SAL OUT NUMBER,HD OUT
DATE)
AS
BEGIN
SELECT FIRST_NAME,SALARY,HIRE_DATE INTO NAME,SAL,HD FROM EMPLOYEES WHERE
EMPLOYEE_ID=ID;
DBMS_OUTPUT.PUT_LINE(NAME);
DBMS_OUTPUT.PUT_LINE(SAL);
DBMS_OUTPUT.PUT_LINE(HD);
END;
DECLARE
X VARCHAR2(30);
Y NUMBER;
Z DATE;
BEGIN
P1(140,X,Y,Z);
END;
DECLARE
X VARCHAR2(30):='85250 00006';
BEGIN
P1(X);
END;
DECLARE
A VARCHAR2(30);
BEGIN
P1(80,A);
END;
FOR LOOP:
BEGIN
P1(80);
END;
USING CURSOR
DECLARE
A VARCHAR2(30);
BEGIN
P1(30,A);
END;
DATA DICTIONARIES: