Example 1:
Output:
A
B
C
DECLARE TYPE var_typ IS TABLE OF VARCHAR2(4000); cVars var_typ; cVar VARCHAR2(4000); BEGIN EXECUTE IMMEDIATE ' SELECT ''A'' cc FROM dual UNION SELECT ''B'' cc FROM dual UNION SELECT ''C'' cc FROM dual' BULK COLLECT INTO cVars; FOR i IN 1 .. cVars.COUNT LOOP cVar := cVars(i); dbms_output.put_line (cVar); END LOOP; END; /
Example 2:
Output:
A C
B D
C E
DECLARE TYPE rec IS RECORD ( col1 VARCHAR2(30), col2 VARCHAR2(30) ); TYPE rec_table IS TABLE OF rec; results rec_table; tRow rec; BEGIN EXECUTE IMMEDIATE ' SELECT ''A'',''C'' FROM dual UNION SELECT ''B'',''D'' FROM dual UNION SELECT ''C'',''E'' FROM dual' BULK COLLECT INTO results; FOR i IN 1 .. results.COUNT LOOP tRow := results(i); dbms_output.put_line(tRow.col1 || ' ' || tRow.col2); END LOOP; END; /