问题描述
假设你通过Hibernate SchemaExport等生成ddl来创建所有的db表等。你得到的是一个脚本,它在开始时以drop语句开始。不是问题,因为我想要这个。但是运行这个脚本会产生一个在Oracle数据库上运行的ORA-00942错误。因为如果表格还不存在,它们并不是真正的错误,所以我希望我的创建脚本在执行时没有错误,所以很容易确定什么(如果有的话)失败。
我有什么选择?我希望因为表可能存在或可能不存在而生成drop语句,但我不想让一百万个ORA-s回到我身上,我必须检查(以确定它们是否是实际的错误),仅仅是因为它不能够'如果你得到一个drop语句的脚本,而Hibernate不会这样做的话,然后,将DROP TABLE语句包装在IF中以测试该表是否存在,然后再放弃它:
IF EXISTS(SELECT NULL
FROM TABLE_XYZ)然后
DROP TABLE TABLE_XYZ;
END IF;
Say you generate ddl to create all your db tables etc via Hibernate SchemaExport etc. What you get is a script which starts with drop statements at the beginning. Not a problem, as I want this. But running this script produces a crapload of ORA-00942 errors running on an Oracle db.
Since they're not really errors if the tables just didn't exist yet, I'd like my create script to be error free when it executes so it's easy to determine what (if any) failed.
What are my options? I DO want drop statements generated since tables may or may not exist yet, but I don't want a million ORA-s coming back at me that I have to check (to determine if they're actual errors) just because it couldn't drop a table that's brand new.
If you get a script of drop statements, and Hibernate won't do it for you then wrap the DROP TABLE statements in an IF to test if the table exists before dropping it:
IF EXISTS(SELECT NULL
FROM TABLE_XYZ) THEN
DROP TABLE TABLE_XYZ;
END IF;
这篇关于在ddl创建脚本中抑制ORA-00942错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!