Oracle 删表前验证表名是否存在并且删除
Posted 博客园站长
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle 删表前验证表名是否存在并且删除相关的知识,希望对你有一定的参考价值。
DECLARE num NUMBER; BEGIN SELECT COUNT(1) INTO num FROM USER_TABLES WHERE TABLE_NAME = UPPER(‘tableName‘) ; IF num > 0 THEN EXECUTE IMMEDIATE ‘DROP TABLE tableName‘ ; END IF; END;
多表情况
declare num number; num1 number; num2 number; begin SELECT COUNT(1) INTO num FROM USER_TABLES WHERE TABLE_NAME = UPPER(‘BAK_XX1‘) ; SELECT COUNT(1) INTO num1 FROM USER_TABLES WHERE TABLE_NAME = UPPER(‘BAK_XX2‘) ; SELECT COUNT(1) INTO num2 FROM USER_TABLES WHERE TABLE_NAME = UPPER(‘BAK_XX3‘) ; if num=1 then execute immediate ‘drop table BAK_XX1‘; end if; if num1=1 then execute immediate ‘drop table BAK_XX2‘; end if; if num1=1 then execute immediate ‘drop table BAK_XX3‘;
以上是关于Oracle 删表前验证表名是否存在并且删除的主要内容,如果未能解决你的问题,请参考以下文章