ITeye博客

Oracle - Add Exist Validation Before Create Table

kylinsoong · 2011-11-07 13:49 · JavaEE · DATABASE · 数据库 · Markdown

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)

暂无评论。

评论功能维护中,当前仅展示历史评论。