How to bind arrays in a variable in PL/SQL
.
For Example i have below array:
array_col3 = {1,2,3,4,5,6,7}
now i want to select
from a table based on the array
.
select * from tabA where col3 in (select * from (:array_col3));
How to bind arrays in a variable in PL/SQL
.
For Example i have below array:
array_col3 = {1,2,3,4,5,6,7}
now i want to select
from a table based on the array
.
select * from tabA where col3 in (select * from (:array_col3));
Hope this below snippet helps.
SET serveroutput ON;
DECLARE
lv sys.odcivarchar2list:=sys.odcivarchar2list('1','2','3','4');
lv1 sys.odcivarchar2list;
BEGIN
SELECT * BULK COLLECT
INTO lv1
FROM
( SELECT LEVEL LVL FROM DUAL CONNECT BY LEVEL < 10
)A
WHERE A.lvl IN
(SELECT COLUMN_VALUE FROM TABLE(LV)
) ;
dbms_output.put_line(lv1.COUNT);
END;
###############################OUTPUT##########################################
anonymous block completed
4
###############################OUTPUT##########################################
You need a table()
expression:
select * from tabA where col3 in (select * from table((:array_col3)));
or alternatively the member of
operator:
select * from tabA where col3 member of :array_col3;
In plsql its not so simple. You have to use types, have a look at dbms_utility package .
Example:
Va dbms_utility.number_array;
Va(1) := 1;
Va(2) := 2;