How to call DDL statements from pl/sql?

Answer Posted / pavan_1981

One can call DDL statements like CREATE, DROP, TRUNCATE,
etc. from PL/SQL by using the "EXECUTE IMMEDATE" statement.
Users running Oracle versions below 8i can look at the
DBMS_SQL package .
begin
EXECUTE IMMEDIATE 'CREATE TABLE X(A DATE)';
end;
NOTE: The DDL statement in quotes should not be terminated
with a semicolon.

Another way is One can also use the older DBMS_SQL package
(V2.1 and above) to execute dynamic statements. Look at
these examples:
CREATE OR REPLACE PROCEDURE DYNSQL AS
cur integer;
rc integer;
BEGIN
cur := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(cur, 'CREATE TABLE X (Y DATE)',
DBMS_SQL.NATIVE);
rc := DBMS_SQL.EXECUTE(cur);
DBMS_SQL.CLOSE_CURSOR(cur);
END;
/


Is This Answer Correct ?    28 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the differences between implicit and explicit cursors?

522


what are ddl statements in mysql? : Sql dba

579


How to use sql*plus built-in timers?

578


Write a query to display the current date in sql?

516


How exception handling is done in advance pl/sql?

501






How do I find duplicates in sql?

509


How do I find duplicates in the same column?

548


Is stored procedure faster than query?

565


How many types of keys are there in sql?

556


What is write ahead logging in sql server?

564


Explain the purpose of %type and %rowtype data types with the example?

554


How do you take the union of two tables in sql?

517


Which one is better subquery or joins?

557


How do I create an index in word?

542


How to read/write files from pl/sql?

582