Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Create a table only if the table doesn't exists

Re: Create a table only if the table doesn't exists

From: DA Morgan <damorgan_at_psoug.org>
Date: Fri, 23 Jun 2006 09:31:04 -0700
Message-ID: <1151080265.87710@bubbleator.drizzle.com>


fred wrote:
> "Mark D Powell" <Mark.Powell_at_eds.com> a écrit dans le message de news:
> 1151005831.800279.287370_at_y41g2000cwy.googlegroups.com...

>> In your pl/sql routine you can select againt all_tables or dba_tables
>> to see if the table exists.  A select count(*) always returns a value
>> so zero would indicate the table does not exist and to run the create
>> table logic while > 0 would tell that the table already exists.

>
> Following your advice, I have written it like this (I prefer to look into
> user_tables to avoid to see others schemas tables):
>
> DECLARE
> tableExists number;
> BEGIN
> -- Check if the table already exists
> SELECT COUNT(*) INTO tableExists FROM user_tables WHERE table_name='XX';
> -- if the table does not exist
> IF tableExists=0 THEN
> -- create it
> execute immediate 'CREATE TABLE XX...';
> END IF;
> END;
>
> Thanks for your help.
> Fred.

Better but still a very bad idea. What is the business case for implementing a known bad practice of creating tables with procedural code?

-- 
Daniel A. Morgan
University of Washington
damorgan_at_x.washington.edu
(replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org
Received on Fri Jun 23 2006 - 11:31:04 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US