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

发布于 2024-10-21 12:39:44 字数 987 浏览 2 评论 0原文

有人知道从 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

有更好的方法吗?

Anyone know of a pure sql method for extracting mapping creation scripts from Oracle? the following SQL returns the right results:

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

But in order to turn this into a single line, I've used a tip from http://dotnetsurfers.com/blog/2008/01/16/concatenating-rows-in-a-table-into-a-single-string-using-sql/ so now I have this:

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;

The problem is that oracle can't concatenate a string if the result is more than 4000 chars. It throws an error:

ORA-01489: result of string concatenation is too long

Is there a better way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南街九尾狐 2024-10-28 12:39:44

下面将提取一个对象的 ddl。

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

The following will pull out the ddl for an object.

select dbms_metadata.get_ddl('object_type_goes_here','object_name_goes_here','owner_goes_here') 
from dual
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文