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;
/

本文提供了一种在Oracle数据库中验证表格是否存在前的PL/SQL实现方式,通过创建并立即删除表格来检查其存在性,确保在创建重复表格时避免错误。
7952

被折叠的 条评论
为什么被折叠?



