SQL>
SQL> set serveroutput on
SQL>
SQL> DECLARE
2 sqlString VARCHAR2(200);
3 codeBlock VARCHAR2(200);
4 BEGIN
5 EXECUTE IMMEDIATE 'CREATE TABLE execute_table (col1 VARCHAR(10))';
6
7 FOR v_Counter IN 1..10 LOOP
8 sqlString :=
9 'INSERT INTO execute_table
10 VALUES (''Row ' || v_Counter || ''')';
11 EXECUTE IMMEDIATE sqlString;
12 END LOOP;
13
14 codeBlock :=
15 'BEGIN
16 FOR v_Rec IN (SELECT * FROM execute_table) LOOP
17 DBMS_OUTPUT.PUT_LINE(v_Rec.col1);
18 END LOOP;
19 END;';
20
21 EXECUTE IMMEDIATE codeBlock;
22
23 EXECUTE IMMEDIATE 'DROP TABLE execute_table';
24 END;
25 /
Row 1
Row 2
Row 3
Row 4
Row 5
Row 6
Row 7
Row 8
Row 9
Row 10
PL/SQL procedure successfully completed.
SQL>
SQL>
SQL>
|