Stored Procedure in Oracle Example With IN OUT Parameter

Below is an example of a stored procedure in Oracle with IN OUT parameter. It will take employee number (i_empno) as IN parameter and will return employee name (o_ename) as OUT parameter.

Stored Procedure IN-OUT Parameter Example

CREATE OR REPLACE PROCEDURE GET_EMP_NAME (i_empno IN emp.empno%TYPE,
o_ename OUT emp.ename%TYPE)
IS
CURSOR c_ename (p_empno emp.empno%TYPE)
IS
SELECT ename
FROM emp
WHERE empno = p_empno;
BEGIN
OPEN c_ename (i_empno);

FETCH c_ename INTO o_ename;

CLOSE c_ename;
END get_emp_name;

Execute Procedure GET_EMP_NAME

SET SERVEROUTPUT ON;
DECLARE
v_name emp.ename%TYPE;
BEGIN
get_emp_name (7566, v_name);
DBMS_OUTPUT.put_line (v_name);
END;

Output

JONES
PL/SQL procedure successfully completed.
Vinish Kapoor
Vinish Kapoor

Vinish Kapoor is a seasoned software development professional and a fervent enthusiast of artificial intelligence (AI). His impressive career spans over 20 years, marked by a relentless pursuit of innovation and excellence in the field of information technology. As an Oracle ACE, Vinish has distinguished himself as a leading expert in Oracle technologies, a title awarded to individuals who have demonstrated their deep commitment, leadership, and expertise in the Oracle community.