Dynamic DQL with DBMS_SQL package : Dynamic SQL statement « PL SQL Statements « Oracle PL/SQL Tutorial






SQL>
SQL> CREATE OR REPLACE PROCEDURE runddl (ddl_in in VARCHAR2)
  2  IS
  3     cur INTEGER:= DBMS_SQL.OPEN_CURSOR;
  4     returnValue INTEGER;
  5  BEGIN
  6     DBMS_SQL.PARSE (cur, ddl_in, DBMS_SQL.NATIVE);
  7     returnValue := DBMS_SQL.EXECUTE (cur);
  8     DBMS_SQL.CLOSE_CURSOR (cur);
  9  EXCEPTION
 10     WHEN OTHERS
 11     THEN
 12        DBMS_OUTPUT.PUT_LINE (
 13           'RunDDL Failure on ' || ddl_in);
 14        DBMS_OUTPUT.PUT_LINE (SQLERRM);
 15        DBMS_SQL.CLOSE_CURSOR (cur);
 16  END;
 17  /

Procedure created.

SQL>
SQL>
SQL>








22.22.Dynamic SQL statement
22.22.1.Dynamic DDL
22.22.2.Dynamic DQL with DBMS_SQL package
22.22.3.Table row counter
22.22.4.An example of code using native dynamic SQL
22.22.5.Create dynamic table
22.22.6.Dynamic PL/SQL