Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve the SQL used to create a view in Oracle?

Tags:

In Oracle, to retrieve the SQL used to create a Function, Package, etc, the user_source view can be queried. However, views are not included in this view - nor do they exist in the underlying sys.source$. To access the text of views, the user_views.text column can be used, but this is not exact because Oracle will re-write some parts of the query, for example it will do glob expansion.

How can I retrieve the SQL used to create a view, exactly as it was entered, without glob expansion?

like image 335
Andrew Avatar asked Apr 25 '14 11:04

Andrew


People also ask

Can you query a view in Oracle?

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.

How do you get DDL of a view in Oracle?

You simply execute dbms_metadata. get_ddl, specify the object names, and Oracle will extract ready-to-use DDL.


1 Answers

You can use the following query:

SELECT VIEW_NAME, TEXT FROM USER_VIEWS; 

or you can use ALL_VIEWS, as in

SELECT VIEW_NAME, TEXT  FROM ALL_VIEWS; 

References:

ALL_VIEWS on Oracle® Database Reference

like image 163
Joseph B Avatar answered Sep 23 '22 04:09

Joseph B