In PL/SQL, how do I declare variable MyListOfValues that contains multiple values (MyValue1, MyValue2, etc.)
SELECT *
FROM DatabaseTable
WHERE DatabaseTable.Field in MyListOfValues
I am using Oracle SQL Developer
ODCINUMBERLIST is a varying array (or varray) of NUMBER. ODCIDATELIST (10g) is an array of DATE, ODCIRAWLIST (10g) is an array of RAW(2000) and ODCIVARCHAR2LIST (10g) is an array of VARCHAR2(4000). Note the inaccurate row count! TABLE is a function that transforms the collection in a table.
1 Answer. Show activity on this post. Yes it is possible to use with clause in cursor. Check the below example.
Create the SQL type like this:
CREATE TYPE MyListOfValuesType AS TABLE OF VARCHAR2(4000);
And then use it in a SQL statement
DECLARE
MyListOfValues MyListOfValuesType;
BEGIN
MyListOfValues := MyListOfValuesType('MyValue1', 'MyValue2');
FOR rec IN (
SELECT *
FROM DatabaseTable
WHERE DatabaseTable.Field in (
SELECT * FROM TABLE(MyListOfValues)
)
)
LOOP
...
END LOOP;
END;
Up until Oracle 11g, this only works with a SQL TABLE
type, not with a PL/SQL TABLE
type. With Oracle 12c, you could also use PL/SQL types.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With