Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check with if an Oracle's view exist in the DB ? Before execute a query

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 in advance

like image 318
MadMad666 Avatar asked Apr 13 '12 19:04

MadMad666


1 Answers

You can always query the Oracle data dictionary. Something like

SELECT COUNT(*)
  FROM all_views
 WHERE view_name = <<the name of the view>>
   AND owner     = <<the owner of the view>>

will tell you whether you have access to a view owned by the specified user with the specified name.

Alternately, you can use a more Java-centric approach. You can create a DatabaseMetaData object from your Connection and call getTables to get a list of all the tables and views that you have access to. You can pass getTables a specific table or view name (or a pattern) to restrict the results.

like image 111
Justin Cave Avatar answered Oct 23 '22 09:10

Justin Cave