那是因为--是的一部分-->分离器而不是一部分->分离。
即使您的数据值具有-->此查询也不应出错。 像下面。
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
说明-这里(在上面的查询中) -> (带空格)不是此处数据的一部分,即--> 。 一旦列由路径conected的regexp_replace替换出现的所有->与-->所以这样你仍然可以拥有-->为您的分隔符,而不是-> 。