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

Home -> Community -> Usenet -> c.d.o.server -> Re: create table

Re: create table

From: <rcarvalho1474_at_my-deja.com>
Date: 2000/07/19
Message-ID: <8l2tfm$l7k$1@nnrp1.deja.com>#1/1

I created it as a procedure because may be there's a lot of columns, so you can edit the procedure, and include the commands to insert the columns.
Create the procedure and then execute it, passing the name of your table as a parameter
Before execute the procedure, do not forget to set arraysize 1, as well as set serveroutput on

CREATE OR REPLACE PROCEDURE CR_TAB (P_TABNAME IN VARCHAR2) IS     FL_EXIST VARCHAR2(1);
begin

    DBMS_OUTPUT.ENABLE;
    SELECT 'N' INTO FL_EXIST FROM DUAL

         WHERE NOT EXISTS
            (SELECT 1 FROM ALL_TABLES
             WHERE TABLE_NAME = P_TABNAME);
    IF FL_EXIST = 'N'
       THEN
           DBMS_OUTPUT.PUT_LINE('CREATE TABLE '||P_TABNAME||' (');
-- here, you include col definitions
           DBMS_OUTPUT.PUT_LINE('COL_1  VARCHAR2(nn)');
           .
           .
           DBMS_OUTPUT.PUT_LINE(');');

    END IF;
END;
/
set serveroutput on
set arraysize 1
spool c:\cr_tab.lst
exec cr_tab ('<name of the table>')
spool off
(edit the spool file)
sqlplus @<spoolfile>

GOOD LUCK! In article <8l276n$3sn$1_at_nnrp1.deja.com>,   shuiho_at_my-deja.com wrote:
> Hi everyone,
>
> I would like to do following:
>
> If the table MYTABLE does not exist then
> create table MYTABLE
> end if;
>
> How can I do this in Oracle SQLPLUS script ? Please help me.
> Thank you.
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>

Sent via Deja.com http://www.deja.com/
Before you buy. Received on Wed Jul 19 2000 - 00:00:00 CDT

Original text of this message

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