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
What is t sql in sql server?
Why select is used in sql?
What is the difference between partitioning and sharding?
When can we use the where clause and the having clause?
Define a temp table?
What does 0 mean in sql?
Why do we need unique key in a table?
Is and as keyword in pl sql?
Is grant a ddl statement?
Can we rollback after truncate?
What is $$ in sql?
What is the difference between a database and a relational database?
What is the use of double ampersand (&&) in sql queries? Give an example
how do you know if your mysql server is alive? : Sql dba
explain the advantages and disadvantages of stored procedure? : Sql dba