Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get VIEW ddl using query

For database re-architecture I need to get DDL of each table and view in the database(Oracle). I don't want to go to property of each table/view and get SQL out of it in SQL Developer.

I successfully got DDL for table using-

select dbms_metadata.get_ddl('TABLE','Table_name','Schema_Name') 
  from dual;

But facing problem with VIEW and MVIEW. Could anyone provide commands/keywords for elements other than table.

Also, I want to export the result in an excel file with first column as TableName and second column as DDL.

like image 422
Mithun Khatri Avatar asked May 07 '14 10:05

Mithun Khatri


People also ask

How can I see DDL of a view?

Double-click the view node to open its Object View tab, Select the DDL sub tab.

How do I view DDL in SQL Developer?

When you model a table in your relational model using Oracle SQL Developer Data Modeler, you are probably very curious as to the code that is being generated to represent that object. You can right-mouse-click on an object and choose 'DDL Preview,' or you can use the keyboard shortcut, Alt+Shift+I.

How can I get DDL package?

You can get any package's get ddl ( create script ) as follows. SQL> SELECT DBMS_METADATA. GET_DDL('PACKAGE','OBJECT_NAME','SCHEMA_NAME') FROM DUAL; You can get any package's body get ddl ( create script ) as follows.


2 Answers

Try the below query for view:

select text from ALL_VIEWS where upper(view_name) like upper(<view_name>);

For mviews:

select query from ALL_MVIEWS where upper(mview_name) like upper(<mview_name>);
like image 192
Sra1 Avatar answered Sep 21 '22 17:09

Sra1


For materialized views use:

select dbms_metadata.get_ddl('MATERIALIZED_VIEW','MView_name','Schema_Name') 
  from dual;

See all supported object types here: DBMS_METADATA: Object Types

like image 29
Alexander Vladykin Avatar answered Sep 19 '22 17:09

Alexander Vladykin