Oracle
 sql >> Database >  >> RDS >> Oracle

PL/SQL - Usa la variabile dell'elenco nella clausola Where In

Usa una raccolta:

CREATE TYPE Varchar2TableType AS TABLE OF VARCHAR2(200);

Oppure usa un tipo integrato come SYS.ODCIVARCHAR2LIST o SYS.ODCINUMBERLIST :

VARIABLE cursor REFCURSOR;

DECLARE
  your_collection SYS.ODCIVARCHAR2LIST := SYS.ODCIVARCHAR2LIST();
BEGIN
  your_collection.EXTEND( 100 );

  your_collection(  1) := 'Some value';
  your_collection(  2) := 'Some other value';
  -- ...
  your_collection(100) := DBMS_RANDOM.STRING( 'x', 20 );

  OPEN :cursor FOR
  SELECT t.*
  FROM   your_table t
         INNER JOIN
         TABLE( your_collection ) c
         ON t.id = c.COLUMN_VALUE;
END;
/

PRINT cursor;