SQL 使用查询获取 VIEW ddl

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23515801/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 01:49:53  来源:igfitidea点击:

Get VIEW ddl using query

sqloracleddldbms-metadata

提问by Mithun Khatri

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.

对于数据库重新架构,我需要获取每个表的 DDL 并在数据库(Oracle)中查看。我不想转到每个表/视图的属性并在 SQL Developer 中从中获取 SQL。

I successfully got DDL for table using-

我成功地获得了用于表的 DDL -

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.

但面临 VIEW 和 MVIEW 的问题。任何人都可以为表格以外的元素提供命令/关键字。

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

另外,我想将结果导出到一个 excel 文件中,第一列为TableName,第二列为 DDL。

回答by Sra1

Try the below query for view:

尝试以下查询查看:

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

For mviews:

对于 mviews:

select query from ALL_MVIEWS where upper(mview_name) like upper(<mview_name>);

回答by Alexander Vladykin

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

在此处查看所有支持的对象类型:DBMS_METADATA:对象类型