Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Oracle regexp_substr skips if empty and returns wrong value

user6248369Jul 24 2018 — edited Jul 24 2018

Hello,

Here's the simple query to illustrate the question:

SELECT regexp_substr('ABC|2222|454545|101010|DEFG' , '[^|]+', 1, 3) str

  FROM dual

/

This works fine and brings the correct result - 454545. But if I remove the second value, for example then the result is wrong - 101010:

SELECT regexp_substr('ABC||454545|101010|DEFG' , '[^|]+', 1, 3) str

  FROM dual

/

The idea is to get the digit only at 3rd position separated by pipe. Or digit only after the second pipe. The output should always be 454545.

And I'd appreciate a brief explanation why it skips. Could Oracle do better in general?

Thank you very much to all.

This post has been answered by Paulzip on Jul 24 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 21 2018
Added on Jul 24 2018
6 comments
3,100 views