Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to extract 456 from the string :123:456: as follows:

select regexp_substr(':123:456:', ':(\d+):', 1, 2, 'i', 1) from dual

However, this query returns null. What am I doing wrong?

share|improve this question
up vote 6 down vote accepted

This works fine:

select regexp_substr(':123:456:', '(\d+):', 1, 2, 'i', 1) from dual;

I think yours fails because the opening and closing colons won't get matched by both occurrences (because the first match is greedy).

share|improve this answer
select regexp_substr(':123:456:','[^:]+',2,2) from dual
share|improve this answer
If this is substantially different from the accepted answer posted by Phil 10 months ago, please add some context explaining why. – Aaron Bertrand Jul 9 '13 at 13:58
This will match on :123:abc: which doesn't sound desirable, but fail to match on ::456: which might be. – Mat Jul 9 '13 at 17:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.