Check table exist or not before create it in Oracle

前端 未结 8 1157
清酒与你
清酒与你 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条回答
  •  梦毁少年i
    2021-02-01 03:18

    Please try:

    SET SERVEROUTPUT ON
    DECLARE
    v_emp int:=0;
    BEGIN
      SELECT count(*) into v_emp FROM dba_tables where table_name = 'EMPLOYEE'; 
    
      if v_emp<=0 then
         EXECUTE IMMEDIATE 'create table EMPLOYEE ( ID NUMBER(3), NAME VARCHAR2(30) NOT NULL)';
      end if;
    END;
    

提交回复
热议问题