0

I have the list of employee_id's as an array. How do I query the table with array in the where clause in PL/SQL?

empIdArray = [1,2,3]

SELECT * FROM EMPLOYEES WHERE EMPLOYEE_ID IN (empIdArray);
2
  • post a minimal reproducible example please Commented Jul 18, 2022 at 16:01
  • SQL or PL/SQL doesn't have an array datatype Commented Jul 18, 2022 at 20:27

1 Answer 1

1

That would be something like this (see line #8):

SQL> declare
  2    empidarray sys.odcinumberlist := sys.odcinumberlist(7369,7499,7521);
  3    l_names    sys.odcivarchar2list;
  4  begin
  5    select ename
  6    bulk collect into l_names
  7    from emp
  8    where empno in (select * from table(empidarray));      --> this
  9
 10    for i in l_names.first .. l_names.last loop
 11      dbms_output.put_line(l_names(i));
 12    end loop;
 13  end;
 14  /
SMITH
ALLEN
WARD

PL/SQL procedure successfully completed.

SQL>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.