where ID IN (vr_arr_list)
It is a Varying IN list of values in WHERE clause. IN (‘1, 2, 3′)
is NOT same as IN (1, 2, 3)
OR IN(‘1′, ‘2’, ‘3’)
. Please see more explanation about Varying IN list of values in WHERE clause.
You could do it in many other ways:
- REGEXP_SUBSTR
- XML
- Table function
- Pipelined function
I have already answered here https://stackoverflow.com/a/26273192/3989608
You could use DBMS_UTILITY.comma_to_table.
SQL> set serveroutput on;
SQL> DECLARE
2 l_tablen BINARY_INTEGER;
3 l_tab DBMS_UTILITY.uncl_array;
4 CURSOR cur
5 IS
6 SELECT 'word1, word2, word3, word4, word5, word6' val FROM dual;
7 rec cur%rowtype;
8 BEGIN
9 OPEN cur;
10 LOOP
11 FETCH cur INTO rec;
12 EXIT
13 WHEN cur%notfound;
14 DBMS_UTILITY.comma_to_table (
15 list => rec.val, tablen => l_tablen, tab => l_tab);
16 FOR i IN 1 .. l_tablen
17 LOOP
18 DBMS_OUTPUT.put_line(i || ' : ' || trim(l_tab(i)));
19 END LOOP;
20 END LOOP;
21 CLOSE cur;
22 END;
23 /
1 : word1
2 : word2
3 : word3
4 : word4
5 : word5
6 : word6
PL/SQL procedure successfully completed.
SQL>
There are also other ways, you could refer my demonstrations here.