Oracle SQL Developer报告使DDL成为DB对象

时间:2016-07-07 09:34:31

标签: sql oracle oracle-sqldeveloper ddl

我为SQL Developer编写了一份报告,用于生成数据库对象的DDL。

SELECT DBMS_METADATA.GET_DDL(UPPER(:OBJECT_TYPE),UPPER(:OBJECT_NAME),UPPER(:OBJECT_SCHEMA)) DDL FROM DUAL
UNION ALL
select DBMS_METADATA.GET_DDL (UPPER('CONSTRAINT'),UPPER(CONSTRAINT_NAME),UPPER(:OBJECT_SCHEMA)) AS "DDL OGGETTI DIPENDENTI" from DBA_CONSTRAINTS where OWNER like UPPER(:OBJECT_SCHEMA) and TABLE_NAME like UPPER(:OBJECT_NAME) and CONSTRAINT_TYPE not like 'R'
UNION ALL
select DBMS_METADATA.GET_DDL (UPPER('REF_CONSTRAINT'),UPPER(CONSTRAINT_NAME),UPPER(:OBJECT_SCHEMA)) from DBA_CONSTRAINTS where OWNER like UPPER(:OBJECT_SCHEMA) and TABLE_NAME like UPPER(:OBJECT_NAME) and CONSTRAINT_TYPE like 'R'
UNION ALL
select DBMS_METADATA.GET_DDL (UPPER('INDEX'),UPPER(INDEX_NAME),UPPER(:OBJECT_SCHEMA)) from DBA_INDEXES where OWNER like UPPER(:OBJECT_SCHEMA) and TABLE_NAME like UPPER(:OBJECT_NAME) 
UNION ALL
select DBMS_METADATA.GET_DEPENDENT_DDL (UPPER('COMMENT'),UPPER(TABLE_NAME),UPPER(:OBJECT_SCHEMA)) from DBA_COL_COMMENTS where OWNER like UPPER(:OBJECT_SCHEMA) and TABLE_NAME like UPPER(:OBJECT_NAME) AND COMMENTS is not null GROUP BY TABLE_NAME
UNION ALL
select DBMS_METADATA.GET_DEPENDENT_DDL (UPPER('OBJECT_GRANT'),UPPER(TABLE_NAME),UPPER(:OBJECT_SCHEMA)) from DBA_TAB_PRIVS where OWNER like UPPER(:OBJECT_SCHEMA) and TABLE_NAME like UPPER(:OBJECT_NAME) GROUP BY TABLE_NAME
UNION ALL
select DBMS_METADATA.GET_DDL (UPPER('SYNONYM'),UPPER(TABLE_NAME),UPPER('PUBLIC')) from DBA_SYNONYMS where TABLE_OWNER like UPPER(:OBJECT_SCHEMA) and TABLE_NAME like UPPER(:OBJECT_NAME) GROUP BY TABLE_NAME
UNION ALL
select DBMS_METADATA.GET_DEPENDENT_DDL (UPPER('TRIGGER'),UPPER(TABLE_NAME),UPPER(:OBJECT_SCHEMA)) from DBA_TRIGGERS where TABLE_OWNER like UPPER(:OBJECT_SCHEMA) and TABLE_NAME like UPPER(:OBJECT_NAME) GROUP BY TABLE_NAME;

函数DBMS_METADATA.GET_DDL的结果类型是CLOB。

问题是当我在记事本或单词中复制字符串输出时:

  • 如果我选择TABLE作为报告样式,则输出的每一行都用" &#34 ;.例如:" CREATE TABLE" MWPROD"。" ORDINI" ...... TABLESPACE" MWPROD_TBSDAT" ;的"
  • 如果我选择SCRIPT作为报告样式,则某些行会被截断。

我想找到一个解决方案来生成一个干净的输出,其中包含没有引号的完整行。

1 个答案:

答案 0 :(得分:1)

DDL由数据库引用 - 它代表了白痴开发人员 - 对不起,开发人员用保留字命名表,如" TABLE",或者需要区分大小写对象的人名称

对于截断的脚本输出,请在脚本中使用SET LONG命令。

SET LONG {80 | N} 设置显示CLOB,LONG,NCLOB和XMLType值的最大宽度(以字节为单位);以及复制LONG值。