加入收藏 | 设为首页 | 会员中心 | 我要投稿 湖南网 (https://www.hunanwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长百科 > 正文

oracle – 当列值中没有sys_connect_by_path定界符时,为什么会得

发布时间:2021-01-12 18:46:39 所属栏目:站长百科 来源:网络整理
导读:我在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,'erewre

我在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;

一些调查:

  • Changing the value “ninechars” to “ninecharsx” allows the query to work
  • Changing the value “ninechars” to “abcdefghi” also breaks the query
    • It seems like all nine character values here break the query
  • Leaving the value as “ninechars” and removing the last union statement,which is not connected to any of the other records,allows
    the query to work
  • Changing the delimiter from ‘ -> ‘ to ‘ *> ‘ allows the query to work


ORA-30004错误的来历是什么?为什么Oracle以为脱离符是作为列值的一部门呈现的?

编辑:感激bobdylan在评述中留下的这个pastebin.com/Ad1edFcJ 链接有助于声名题目

办理要领

这闻起来像一个臭虫.假如你必要办理它并实现你的逻辑,可能你可以行使递归子查询因子(recursive With),它在11.2.0.4中正常事变:

SQL> with t (id,label,parentid,reportlevel,fake_connect_by_path) as (
  2  select id,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

(编辑:湖南网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读