码迷,mamicode.com
首页 > 数据库 > 详细

Oracle 删表前验证表名是否存在并且删除

时间:2016-06-28 18:28:25      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:

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 删表前验证表名是否存在并且删除

标签:

原文地址:http://www.cnblogs.com/wdw31210/p/5624228.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!