DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: create table or insert into table

  1. #1
    Join Date
    Dec 2002
    Posts
    28

    create table or insert into table

    How can I check if table exists and if not create one else insert into table. Please advise. See example below as create command fails as expects end etc..
    DECLARE

    counter INTEGER := 0;
    mytotal INTEGER := 0;

    BEGIN

    SELECT
    COUNT( 1 )
    INTO
    counter
    FROM
    user_tables
    WHERE
    table_name like 'testing';

    mytotal := mytotal + counter;


    IF ( mytotal != 0 ) THEN
    INSERT
    INTO testing (implemented)
    VALUES ('testing123');
    Else
    CREATE TABLE testing (
    implemented varchar2 (40),
    date_run date
    )
    TABLESPACE mytblspace;



    END;
    /

  2. #2
    Join Date
    Nov 2002
    Location
    Geneva Switzerland
    Posts
    3,142
    You will need to use dynamic SQL for DDL i.e. the Create statement. Look up EXECUTE IMMEDIATE in the doc.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width