Home  >  Article  >  Database  >  Oracle 删除表前判断表名是否存在

Oracle 删除表前判断表名是否存在

WBOY
WBOYOriginal
2016-06-07 17:33:251502browse

在Oracle中若删除一个不存在的表,如 DROP TABLE notExistTable,则会提示:ORA-00942:表或视图不存在,若使用程序执行该语句则会报

在Oracle中若删除一个不存在的表,如 "DROP TABLE notExistTable",则会提示:

ORA-00942:表或视图不存在,

若使用程序执行该语句则会报异常,这就需要我们再删除表前判断该表是否存在,若存在则删除.

下面是不使用存储过程实现删除表的SQL:

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;

相关阅读:

删除表空间报错ORA-600(ktssdrp1)错误

Oracle 删除表名命名不合法的表

Linux下Oracle删除表空间引发错误的解决方法

Oracle 误删除表数据恢复

Oracle利用rowid删除表中重复记录

Oracle无法删除表

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Oracle 10g 安装图解教程Next article:Oracle的Lpad函数