如果sql语句中存在表,则从oracle数据库中删除表 [英] Drop table from oracle database if table exist in sql statement

查看:433
本文介绍了如果sql语句中存在表,则从oracle数据库中删除表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用SQL语句删除表,如果表不存在,它将崩溃.是否可以使用IF语句删除表 s.executeUpdate("DROP TABLE employee");

I have to use an SQL statement to drop a table, it will crash if the table doesn't exist. Is it possible to use IF statement to drop the table s.executeUpdate("DROP TABLE employee");

推荐答案

Oracle不支持类似drop table if exists my_table的结构,这显然是MySQL(甚至可能是其他RDBMS)中的合法语法.

Oracle does not support a construct like drop table if exists my_table, which is apparently legal syntax in MySQL (and possibly other RDBMSs).

.SQL脚本中,在运行DDLDROP和/或CREATE各种对象的地方,Oracle标准是删除该对象,并在该对象发生错误的情况下忽略该错误.不存在.如果需要,您可以编写代码来检查对象是否存在(请参见DBA_OBJECTS视图),仅在对象存在时丢弃.

In a .SQL script, where you're running DDL to DROP and/or CREATE various objects, the Oracle standard is to drop the object, and ignore the error in cases where the object does not exist. If you wish, you can write code to check if the object exists (see DBA_OBJECTS view) to only drop if it exists.

,我知道您正在Java中执行此操作?如果是我,那么我只需要执行删除操作,然后忽略任何不存在的错误即可.

from the s.executeUpdate, I gather that you're doing this in Java? If it was me, I'd just do the drop and ignore any not exists error.

希望有帮助.

这篇关于如果sql语句中存在表,则从oracle数据库中删除表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆