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

Why should I use postgresql?

561


What is your daily office routine?

1808


What is count * in sql?

551


Which join is like an inner join?

523


Explain how to use transactions efficiently : transact sql

527






how to get a list of columns in an existing table? : Sql dba

540


What is the most restrictive isolation level? : Transact sql

554


What is a full join?

521


Can a key be both primary and foreign?

508


Where not exists in sql?

503


What is a ddl command?

532


What is sql query optimization?

541


what is difference between delete and truncate commands? : Sql dba

575


What are field types?

535


What are stored procedures in mysql?

558