时间:2021-07-01 10:21:17 帮助过:2人阅读
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 删表前验证表名是否存在并且删除
标签: