Check table exist or not before create it in Oracle

前端 未结 8 1233
清酒与你
清酒与你 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:35

    Well there are lot of answeres already provided and lot are making sense too.

    Some mentioned it is just warning and some giving a temp way to disable warnings. All that will work but add risk when number of transactions in your DB is high.

    I came across similar situation today and here is very simple query I came up with...

    declare
    begin
      execute immediate '
        create table "TBL" ("ID" number not null)';
      exception when others then
        if SQLCODE = -955 then null; else raise; end if;
    end;
    /
    

    955 is failure code.

    This is simple, if exception come while running query it will be suppressed. and you can use same for SQL or Oracle.

提交回复
热议问题