提取仓库映射作为创建脚本
有人知道从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下面将提取一个对象的 ddl。
The following will pull out the ddl for an object.