I just found out that one of the queries I am running is not coming from actual table, it is coming from a VIEW.
I would like to see the SQL query in that VIEW. If I try to describe
I get an object does not exist error. When I SELECT from the view I get some data.
replace VIEW_NAME with the name of your view. Object_type='VIEW' should not be changed. select * from schema. view_name; , schema is the DB User or owner.
Views in SQL are kind of virtual tables. A view also has rows and columns as they are in a real table in the database. We can create a view by selecting fields from one or more tables present in the database. A View can either have all the rows of a table or specific rows based on certain condition.
A view is a virtual table because you can use it like a table in your SQL queries. Every view has columns with data types so you can execute a query against views or manage their contents (with some restrictions) using the INSERT , UPDATE , DELETE , and MERGE statements. Unlike a table, a view does not store any data.
To see the SQL underlying a view, you'll need to query the data dictionary. Try
select view_name, text from user_views where view_name = 'MY_VIEW';
If your user does not own the view, then try all_views
;
If you would like to see the actual SQL used to create the view you can use the function dbms_metadata.get_ddl
, which returns a clob:
select dbms_metadata.get_ddl ( 'VIEW'
, 'MY_VIEW' -- view name
)
from dual
There are a few more options if you need them.
If you want to just describe it as usual. If this is not working you're in the wrong schema or the object does not exist:
DESC MY_VIEW
If you're in the incorrect schema you can use:
select dbms_metadata.get_ddl ( 'VIEW'
, 'MY_VIEW', -- view name
, 'MY_SCHEMA'
)
from dual
or
DESC MY_SCHEMA.MY_VIEW
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With