First DBMS_SQL Example
SQL>
SQL>
SQL> CREATE OR REPLACE PROCEDURE RecreateTempTable (
2 p_Description IN VARCHAR2) IS
3
4 v_Cursor NUMBER;
5 v_CreateString VARCHAR2(100);
6 v_DropString VARCHAR2(100);
7 v_NumRows INTEGER;
8 BEGIN
9 v_Cursor := DBMS_SQL.OPEN_CURSOR;
10
11 v_DropString := 'DROP TABLE MyTable';
12
13 BEGIN
14 DBMS_SQL.PARSE(v_Cursor, v_DropString, DBMS_SQL.V7);
15 v_NumRows := DBMS_SQL.EXECUTE(v_Cursor);
16 EXCEPTION
17 WHEN OTHERS THEN
18 IF SQLCODE != -942 THEN
19 RAISE;
20 END IF;
21 END;
22 v_CreateString := 'CREATE TABLE MyTable ' || p_Description;
23 DBMS_SQL.PARSE(v_Cursor, v_CreateString, DBMS_SQL.V7);
24 v_NumRows := DBMS_SQL.EXECUTE(v_Cursor);
25
26 DBMS_SQL.CLOSE_CURSOR(v_Cursor);
27 EXCEPTION
28 WHEN OTHERS THEN
29 DBMS_SQL.CLOSE_CURSOR(v_Cursor);
30 RAISE;
31 END RecreateTempTable;
32 /
Procedure created.
SQL>
Related examples in the same category