我在Oracle版本上测试了这个:
11.2.0.3.0
12.1.0.2.0
以下查询引发ORA-30004错误,但我的分隔符是' - > '未在任何列值中使用:
with temptable as (
select '2624' as id, 'ninechars' as label, '' as parentid from dual union
select '2625' as id, 'erewrettt' as label, '2624' as parentid from dual union
select '2626' as id, 'Im stumped' as label, '' as parentid from dual union
select '2627' as id, '- Unknown -' as label, '' as parentid from dual
)
select sys_connect_by_path(label, ' -> ' )
from temptable
start with parentid is null
connect by prior id = parentid;
一些观察结果:
- 改变价值"九岔" to" ninecharsx"允许查询工作
- 改变价值"九岔" to" abcdefghi"也打破了查询
- 似乎这里的所有九个字符值都会破坏查询
- 将价值保留为"九个"并删除最后一个未连接到任何其他记录的union语句允许 要运行的查询
- 更改'的分隔符 - > '到' * GT; '允许查询工作
的问题
ORA-30004错误的来源是什么?为什么Oracle认为分隔符是作为列值的一部分出现的?
编辑:感谢bobdylan在评论中留下的pastebin.com/Ad1edFcJ 链接有助于说明问题
答案 0 :(得分:1)
这闻起来像个臭虫。如果你需要解决它并实现你的逻辑,或者你可以使用递归子查询因子(递归With),它在11.2.0.4中正常工作:
SQL> with t (id, label, parentid, reportlevel, fake_connect_by_path) as (
2 select id, label, parentid, 0 as reportlevel, ' -> ' || label as fake_connect_by_path
3 from temptable
4 where parentid is null
5 union all
6 select tt.id, tt.label, tt.parentid, reportlevel + 1, t.fake_connect_by_path || ' -> ' || tt.label as fake_connect_by_path
7 from temptable tt
8 join t on t.id = tt.parentid
9 )
10 select fake_connect_by_path
11 from t;
FAKE_CONNECT_BY_PATH
--------------------------------------------------------------------------------
-> ninechars
-> Im stumped
-> - Unknown -
-> ninechars -> erewrettt