使用SYS_CONNECT_BY_PATH函数时Oracle ORA-30004,

前端之家收集整理的这篇文章主要介绍了使用SYS_CONNECT_BY_PATH函数时Oracle ORA-30004,前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
ORA-30004在使用SYS_CONNECT_BY_PATH函数时,不能将分隔符作为列的一部分

Action: Use another seperator which does not occur in any column
value,then retry.

错误

  1. select ...
  2. Sys_Connect_By_Path(myVariable || ':' || mySecondVariable,' --> ') "myNewVar",...

作品:

  1. select ...
  2. Sys_Connect_By_Path(myVariable || ':' || mySecondVariable,' -> ') "myNewVar",...

在数据中,我们发现了一些这样的文字

> SomeText B – 更多文字
> SomeText A – 更多文字

由于没有’ – >’或者那个母亲没有’ – >’在数据中为什么第一个错误?第二个在前面和末端有一个空间.

那是因为 – 是 – >的一部分分隔符但不是 – >的一部分分隔器.

即使您的数据值为 – >这个查询不应该出错.如下.

  1. sql> select Sys_Connect_By_Path('SomeText B-->More Text' || ':' || 'SomeText A-->More Text',' --> ') "myNewVar"
  2. from dual
  3. connect by rownum<=3;
  4.  
  5. myNewVar
  6. ----------------------------------------------------
  7. --> SomeText B-->More Text:SomeText A-->More Text
  8. --> SomeText B-->More Text:SomeText A-->More Text --> SomeText B-->More Text:SomeText A-->More Text
  9. --> 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).整个字符串不是数据或列值的一部分.

如下所示会出错

  1. sql> select Sys_Connect_By_Path('SomeText B-->More Text' || ':' || 'SomeText A-->More Text','-->') "myNewVar"
  2. from dual
  3. connect by rownum<=3;
  4.  
  5. ORA-30004: when using SYS_CONNECT_BY_PATH function,cannot have seperator as part of column value
  6. 30004. 00000 - "when using SYS_CONNECT_BY_PATH function,cannot have seperator as part of column value"
  7. *Cause:
  8. *Action: Use another seperator which does not occur in any column value,then retry.

上面的分隔符是 – >,注意没有空格,即chr(45)|| chr(45)|| chr(62).整个字符串确实是数据或列值的一部分,因此也就是错误.

这是一个解决方案(未经测试的性能)

  1. select regexp_replace(Sys_Connect_By_Path('SomeText B-->More Text' || ':' || 'SomeText A-->More Text',' -> '),' -> ','-->') "myNewVar"
  2. from dual
  3. connect by rownum<=3;
  4.  
  5. myNewVar
  6. --------------------------------------
  7. -->SomeText B-->More Text:SomeText A-->More Text
  8. -->SomeText B-->More Text:SomeText A-->More Text-->SomeText B-->More Text:SomeText A-->More Text
  9. -->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将替换所有出现的 – >用 – >所以你仍然可以这样做 – >作为您的分隔符而不是 – >.

猜你在找的Oracle相关文章