0
A
回答
1
Oracle有一个all_tables
表,你可以查询看看。
也许是这样的:
declare
v_tab_count number := 0;
begin
select count(*)
into v_tab_count
from all_tables
where table_name = 'MY_TABLE';
if v_tab_count > 0 then
execute immediate 'drop table my_table';
else
dbms_output.put_line('The table isn''t there! maybe you deleted it already?');
end if;
exception
when others then
dbms_output.put_line(sqlerrm);
end if;
/
我知道我刚才在别人的帖子评论说,我不喜欢使用execute immediate
这一点,但我忘了这是执行drop table
的唯一途径来自PL/SQL。
1
2
http://www.dba-oracle.com/bk_check_table_exists.htm
这里有给出不同的解决方案。最简单的:
SQL>递减MYTABLE
或者只是尝试删除并捕获异常:
begin
execute immediate 'drop table TABLE1';
exception when others then null;
end;
+0
DROP替代方案真的很糟糕,忽略了一个显而易见的事实,即想知道表是否存在是最常见的事情,因为它想要拥有它! – Mirvnillith 2012-12-20 06:47:15
相关问题
- 1. 确定ORACLE表中是否存在字段的快速方法
- 2. 确定Oracle日期是否在周末?
- 3. 检查Oracle表是否与Puppet存在
- 4. 使用SQL查询,以确定是否一个表存在
- 5. PySVN - 确定是否存在存储库
- 6. Oracle - 如何确定表是否是TDE加密
- 7. 确定html表中是否存在确切的行
- 8. 确定是否在emberjs存在模板
- 9. 如何确定Crystal报表中是否存在自定义Ufl?
- 10. 确定文件夹是否存在?
- 11. 确定是否存在选择
- 12. 确定元素是否存在
- 13. 确定是否存在XDocument文件
- 14. NSTextView确定是否存在NSTextAttachment
- 15. 确定Node.js中是否存在SQLite行
- 16. 确定邻居是否存在?
- 17. LINQ,以确定是否孩子存在
- 18. SQL查询,以确定Oracle空间表是否包含曲线
- 19. 如何确定Oracle表是否设置了ROWDEPENDENCIES选项?
- 20. 确定表存在
- 21. 确定存储过程是否存在于任何地方?
- 22. 确定执行EF迁移时是否存在表格
- 23. Tapestry,确定表单是否存在tml中的错误
- 24. 确定一个文件列表是否存在于Haskell
- 25. 确定表单上是否存在字段
- 26. MySQL:确定多个表中是否存在日期
- 27. 确定SQL Server CE中是否存在表?
- 28. 在Oracle中创建它之前检查表是否存在
- 29. 在多个用户的oracle/oracle表单中验证数据是否存在
- 30. 确定Web存储是否受支持
太好了! User_Tables和All_tables(如果2个用户具有相同的表,则计数可以为2)使用User_tables会更好吗? – kalls 2011-06-15 17:56:44
@ kalls:你可以在all_tables或user_tables的查询中添加一些额外的条件? – FrustratedWithFormsDesigner 2011-06-15 18:10:24