You are getting that error, obviously, because someid
is of number datatype and you are passing a comma separated string, which is considered as one value of string datatype and not a list of values as you would expect, to the IN
clause. But you can transform that string, using regexp_substr and regexp_count regular expression functions, into table rows an then use them in the IN
clause. Here is an example:
SQL> declare
2 cursor your_cursor(c_str_value varchar2) is
3 with str_values as(
4 select regexp_substr(c_str_value, '[^,]+', 1, level) as value
5 from dual
6 connect by level <= regexp_count(c_str_value, '[^,]+')
7 )
8 select first_name -- here goes your query
9 from employees e
10 where e.department_id in (select to_number(value)
11 from str_values);
12
13 l_local_var varchar2(20);
14 begin
15 l_local_var := '100,102,103'; -- your comma separated string
16 for i in your_cursor(l_local_var) -- for the sake of demonstration
17 loop
18 dbms_output.put_line(i.first_name);
19 end loop;
20 end;
21 /
Nancy
Daniel
John
Ismael
Jose Manuel
Luis
PL/SQL procedure successfully completed