加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Oracle Drop Table If Exists

发布时间:2020-12-12 15:51:21 所属栏目:百科 来源:网络整理
导读:Sometimes we want to clean up Oracle database,such as to drop a table if there exists,and do nothing if table does not exist; such as: - drop table table if exists Unfortunately,there is no such statement we can use,although this is suppor

Sometimes we want to clean up Oracle database,such as to drop a table if there exists,and do nothing if table does not exist; such as:

- drop table table if exists


Unfortunately,there is no such statement we can use,although this is supported by other RDBMS,such as MySQL,but not Oracle.


As a workaround,we can use catching the "table not found" exception:


BEGIN EXECUTE IMMEDIATE 'DROP TABLE yourtablename'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN RAISE; END IF; END;


The same solution can be used for other Oracle object types: sequence,function,etc. (just pay attention to the different SQLCODE value)


Reference:

1. http://stackoverflow.com/questions/1799128/oracle-if-table-exists
2. http://ora-exp.blogspot.jp/2013/03/oracle-drop-table-if-exists.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读