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

how to calculate the difference between two dates? : Sql dba

721


What is composite primary key in sql?

710


How does a trigger work?

715


What are the different types of constraints?

740


What is the difference between microsoft access and sql server?

709






what are all different types of collation sensitivity? : Sql dba

708


What is the syntax to add a record to a table?

780


What are the rules to be applied to nulls whilst doing comparisons?

980


Can we call stored procedure in function?

704


what happens if null values are involved in expressions? : Sql dba

734


Is left join faster than inner join?

831


What is sql basics?

781


What is the difference between numeric and autonumber?

692


What are the types of variables use in pl sql?

687


What view means?

730