Oracle: If Table Exists

后端 未结 15 1313
无人共我
无人共我 2020-11-22 13:32

I\'m writing some migration scripts for an Oracle database, and was hoping Oracle had something similar to MySQL\'s IF EXISTS construct.

Specifically, w

15条回答
  •  逝去的感伤
    2020-11-22 14:24

    Another method is to define an exception and then only catch that exception letting all others propagate.

    Declare
       eTableDoesNotExist Exception;
       PRAGMA EXCEPTION_INIT(eTableDoesNotExist, -942);
    Begin
       EXECUTE IMMEDIATE ('DROP TABLE myschema.mytable');
    Exception
       When eTableDoesNotExist Then
          DBMS_Output.Put_Line('Table already does not exist.');
    End;
    

提交回复
热议问题