We help IT Professionals succeed at work.
Get Started

Convert CSV to list in oracle for IN-Clause

Last Modified: 2017-05-17
My procedure is passed a comma-separated list of IDs, for example 7369,7499,7839,7902. I tried to use it in my code like this:

   p_empno_list constant varchar2(20) := '7369,7499,7839,7902';
   for r in (
      select * from emp
      where  empno in (p_empno_list)
      dbms_output.put_line(rpad(r.empno,9) || r.ename);
   end loop;
but it just gives me an error:1 When SQL is expecting a character string such as SMITH, but is passed a comma-separated list such as SMITH,JONES,FORD,MILLER, no error is produced, but the query simply returns no rows.

ERROR at line 1:
ORA-01722: invalid number
ORA-06512: at line 4

How can i convert CSV to list so that it can be accepted in IN- clause?
Watch Question
Top Expert 2008
This problem has been solved!
Unlock 6 Answers and 6 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE