ORA-30004在使用SYS_CONNECT_BY_PATH函数时,不能将分隔符作为列的一部分
Action: Use another seperator which does not occur in any column
value,then retry.
错误:
- select ...
- Sys_Connect_By_Path(myVariable || ':' || mySecondVariable,' --> ') "myNewVar",...
作品:
- select ...
- Sys_Connect_By_Path(myVariable || ':' || mySecondVariable,' -> ') "myNewVar",...
在数据中,我们发现了一些这样的文字
> SomeText B – 更多文字
> SomeText A – 更多文字
由于没有’ – >’或者那个母亲没有’ – >’在数据中为什么第一个错误?第二个在前面和末端有一个空间.
那是因为 – 是 – >的一部分分隔符但不是 – >的一部分分隔器.
即使您的数据值为 – >这个查询不应该出错.如下.
- sql> select Sys_Connect_By_Path('SomeText B-->More Text' || ':' || 'SomeText A-->More Text',' --> ') "myNewVar"
- from dual
- connect by rownum<=3;
- myNewVar
- ----------------------------------------------------
- --> SomeText B-->More Text:SomeText A-->More Text
- --> SomeText B-->More Text:SomeText A-->More Text --> SomeText B-->More Text:SomeText A-->More Text
- --> SomeText B-->More Text:SomeText A-->More Text --> SomeText B-->More Text:SomeText A-->More Text --> SomeText B-->More Text:SomeText A-->More Text
上面的分隔符是 – >,注意空格.该空白被认为是分隔符的一部分,即chr(1)|| chr(45)|| chr(45)|| chr(62)|| chr(1).整个字符串不是数据或列值的一部分.
如下所示会出错
- sql> select Sys_Connect_By_Path('SomeText B-->More Text' || ':' || 'SomeText A-->More Text','-->') "myNewVar"
- from dual
- connect by rownum<=3;
- ORA-30004: when using SYS_CONNECT_BY_PATH function,cannot have seperator as part of column value
- 30004. 00000 - "when using SYS_CONNECT_BY_PATH function,cannot have seperator as part of column value"
- *Cause:
- *Action: Use another seperator which does not occur in any column value,then retry.
上面的分隔符是 – >,注意没有空格,即chr(45)|| chr(45)|| chr(62).整个字符串确实是数据或列值的一部分,因此也就是错误.
- select regexp_replace(Sys_Connect_By_Path('SomeText B-->More Text' || ':' || 'SomeText A-->More Text',' -> '),' -> ','-->') "myNewVar"
- from dual
- connect by rownum<=3;
- myNewVar
- --------------------------------------
- -->SomeText B-->More Text:SomeText A-->More Text
- -->SomeText B-->More Text:SomeText A-->More Text-->SomeText B-->More Text:SomeText A-->More Text
- -->SomeText B-->More Text:SomeText A-->More Text-->SomeText B-->More Text:SomeText A-->More Text-->SomeText B-->More Text:SomeText A-->More Text
说明 – 此处(在上面的查询中) – > (带空格)不是这里数据的一部分,即 – >.一旦列被路径连接,regexp_replace将替换所有出现的 – >用 – >所以你仍然可以这样做 – >作为您的分隔符而不是 – >.