Check table exist or not before create it in Oracle

前端 未结 8 1167
清酒与你
清酒与你 2021-02-01 03:07

Trying to check is table exist before create in Oracle. Search for most of the post from Stackoverflow and others too. Find some query but it didn\'t work for me.



        
8条回答
  •  难免孤独
    2021-02-01 03:13

    -- checks for table in specfic schema:

    declare n number(10);
    
    begin
        Select count(*) into n  from SYS.All_All_Tables where owner = 'MYSCHEMA' and TABLE_NAME =  'EMPLOYEE';
    
       if (n = 0) then 
         execute immediate 
         'create table MYSCHEMA.EMPLOYEE ( ID NUMBER(3), NAME VARCHAR2(30) NOT NULL)';      
       end if;
    end;
    

提交回复
热议问题