`
kylinsoong
  • 浏览: 236136 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Oracle - Add Exist Validation Before Create Table

阅读更多

Usually we need to check the table is exist or not before create a new table, In Mysql database, that's very easy, 'cause mysql default sql statement support exist check, But in Oracle it's quite complicated. the following is a solution to validate the table is existable before create it in Oracle Platform:

Assuming APPVersion table already exist in database through the following sql statement:

create table AppVersion (
  NAME varchar2(30) primary key not null,
  VERSION varchar2(30) not null,
  INSTALLED DATE not null
);

The Following PL/SQL can implement exist validation before create  table APPVersion duplicated:

DECLARE
BEGIN   
  EXECUTE IMMEDIATE 'DROP TABLE APPVERSION';
  EXCEPTION WHEN OTHERS THEN NULL;
  COMMIT;
END;
/

 

0
2
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics