将仓库映射提取为创建脚本

时间:2011-03-09 17:36:25

标签: sql oracle string

有人知道从Oracle提取映射创建脚本的纯SQL方法吗?以下SQL返回正确的结果:

SELECT text FROM dba_source WHERE NAME = 'MAPPING_NAME' AND TYPE = 'PACKAGE';

但是为了把它变成一行,我使用了http://dotnetsurfers.com/blog/2008/01/16/concatenating-rows-in-a-table-into-a-single-string-using-sql/的提示,所以现在我有了这个:

SELECT SYS_CONNECT_BY_PATH(text, ' ') PackageScript FROM (
  SELECT text, ROW_NUMBER() OVER (order by line) rownumber, COUNT(*) OVER () cnt
  FROM (SELECT text, line FROM dba_source WHERE NAME = 'MAPPING_NAME' AND TYPE = 'PACKAGE' AND substr(text, 0,2) != '--' AND text IS NOT NULL)
) data
WHERE rownumber = cnt
START WITH rownumber = 1
CONNECT BY PRIOR rownumber = rownumber-1;

问题是如果结果超过4000个字符,oracle无法连接字符串。它抛出一个错误:

ORA-01489: result of string concatenation is too long

有更好的方法吗?

1 个答案:

答案 0 :(得分:4)

以下内容将拉出对象的ddl。

select dbms_metadata.get_ddl('object_type_goes_here','object_name_goes_here','owner_goes_here') 
from dual