How to call DDL statements from pl/sql?

Answer Posted / kavitha nedigunta

set serveroutput on;
DECLARE
CNT NUMBER;
table_name varchar2(300) := 'testnew';
BEGIN
--EXECUTE IMMEDIATE ('grant create table to user_name');
EXECUTE IMMEDIATE ('create table '||table_name||'(name
varchar2(10))');

SELECT COUNT(*) INTO CNT FROM USER_OBJECTS WHERE OBJECT_NAME = upper(''||table_name||'');

IF cnt > 0 THEN
dbms_output.put_line('Table Created');
END IF;

EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('Name is already used by an existing object');
END;

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between a subquery and a join?

558


What are character functions?

667


Can I join the same table twice?

556


What are the ways on commenting in a pl/sql code?

540


Can we have two clustered index on a table?

598






Explain what is an index?

630


what is a view? : Sql dba

663


How many joins can you have in sql?

564


Why is pl sql used?

561


What is trigger types in sql?

565


Explain the commit statement.

637


What is the command used to fetch the first 5 characters of a string?

737


How do I truncate a word?

556


What are the popular database management systems in the it industry?

596


What is difference between sql and excel?

544