如何检查Oracle的视图是否存在于DB中?在执行查询之前 [英] How to check with if an Oracle's view exist in the DB ? Before execute a query
本文介绍了如何检查Oracle的视图是否存在于DB中?在执行查询之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要知道一种从Java桌面应用程序检查的方法,如果在执行查询之前Oracle的视图存在于当前数据库中,否则我会遇到很多麻烦...
I need to know a way to check from a Java Desktop App, if a Oracle's view exist in the current DB before execute a query otherwise I will get a lot of troubles...
感谢提前
推荐答案
感谢大家,最后我得到了一个解决这个问题的方法,谢谢您的建议,代码如下:
Thanks to everyone, finally I got a method that solves this issue, thanks for your suggestions, the code is the following:
public boolean existViewInDB(String viewName) {
logger.debug("[boolean existViewInDB(String viewName[" + viewName
+ "])]");
boolean existView = false;
try {
String sql =
"SELECT count(*) FROM user_views WHERE view_name = :viewName";
SQLQuery query = getSession().createSQLQuery(sql);
query.setString("viewName", viewName);
BigDecimal totalOfViews = (BigDecimal) query.uniqueResult();
existView = (totalOfViews.longValue() > 0);
} catch (Exception e) {
logger.error(e, e);
}
logger.debug("Exist View [" + viewName + "] ? -> " + existView);
return existView;
}
:)
这篇关于如何检查Oracle的视图是否存在于DB中?在执行查询之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文