Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PL/SQL - Create table??

Status
Not open for further replies.

Nick366

MIS
Jan 28, 2004
20
US
Is it possible to create a table within a PL/SQL block? Basically I am checking user_tables to see if a table exists, and if it doesn't then I am creating it.

Code:
declare
	v_count number;
begin
	select count(*) into v_count from user_tables
		where table_name = 'TEMP_2YEAR_DRIVER';

	if v_count = 0 then
		create table temp_2year_driver as (
			select A, B, C
			from subscriber);
	end if;
commit;
end;

 
A couple of options.

If its forms PL/SQL
try using Forms_ddl built-in or the exec_sql package

If its regular PL/SQL just use execute immediate ' create tabe ...'
 
In any case you don't need commit as any DDL statement ends your transaction. Then, even if that table already exists then an attempt to create it again just fails even faster then searching throug user_tables. So you may catch an error and process ( ignore :) ) it.


Regards, Dima
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top