DBMS_SQL.PARSE and DBMS_SQL.EXECUTE
SQL>
SQL> SET ECHO ON
SQL> SET SERVEROUTPUT ON
SQL>
SQL> DECLARE
2 v_CursorID NUMBER;
3 v_CreateTableString VARCHAR2(500);
4 v_NUMRows INTEGER;
5
6 BEGIN
7 v_CursorID := DBMS_SQL.OPEN_CURSOR;
8 v_CreateTableString := 'CREATE TABLE MyTable(MyRow INTEGER, MyDesc VARCHAR2(50))';
9
10 DBMS_SQL.PARSE(v_CursorID,v_CreateTableString,DBMS_SQL.V7);
11 v_NumRows := DBMS_SQL.EXECUTE(v_CursorID);
12
13 EXCEPTION
14 WHEN OTHERS THEN
15 IF SQLCODE != -955 THEN -- 955 is error that table exists
16 RAISE;
17 ELSE
18 DBMS_OUTPUT.PUT_LINE('Table Already Exists!');
19 END IF;
20 DBMS_SQL.CLOSE_CURSOR(v_CursorID);
21 END;
22 /
PL/SQL procedure successfully completed.
SQL>
SQL> drop table mytable;
Table dropped.
SQL>
SQL> --
Related examples in the same category