Oracle – Pass Value to IN query in Procedure | Code Factory


Donate : Link

Medium Blog : Link

Applications : Link

Table Structure :

CREATE TABLE Emp (
     EMP_CODE number(5),
     EMP_NAME varchar2(25),
     EMP_AGE number(5)
);

Insert Data :

insert into emp(emp_code, emp_name, emp_age) values(101, 'JAN', 1);
insert into emp(emp_code, emp_name, emp_age) values(102, 'FEB', 2);
insert into emp(emp_code, emp_name, emp_age) values(103, 'MAR', 3);
insert into emp(emp_code, emp_name, emp_age) values(104, 'APR', 4);
insert into emp(emp_code, emp_name, emp_age) values(105, 'MAY', 5);

Procedure :

CREATE OR REPLACE PROCEDURE "SEARCH_EMP" (EMP_IDS IN VARCHAR2)
IS
BEGIN
       FOR i in (SELECT EMP_NAME FROM EMP
             WHERE EMP_CODE IN 
             (SELECT REGEXP_SUBSTR(EMP_IDS,'[^,]+', 1, LEVEL) FROM DUAL CONNECT BY REGEXP_SUBSTR(EMP_IDS, '[^,]+', 1, LEVEL) IS NOT NULL )) 
       LOOP
           DBMS_OUTPUT.PUT_LINE('EMP_NAME : ' || i.EMP_NAME);
       END LOOP;
end SEARCH_EMP;

Call Procedure :

CALL SEARCH_EMP('102,103');

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s