Re: Regular Expressions; return a buried match
From: Maxim Demenko <mdemenko_at_gmail.com>
Date: Thu, 04 Feb 2010 08:28:10 +0100
Message-ID: <4B6A770A.7060403_at_gmail.com>
On 03.02.2010 23:43, cate wrote:
> select REGEXP_SUBSTR(encodedField, '^\d{4}(\d\d)') from table;
>
> I want the 5th and 6th digit. Can Oracle do this?
Date: Thu, 04 Feb 2010 08:28:10 +0100
Message-ID: <4B6A770A.7060403_at_gmail.com>
On 03.02.2010 23:43, cate wrote:
> select REGEXP_SUBSTR(encodedField, '^\d{4}(\d\d)') from table;
>
> I want the 5th and 6th digit. Can Oracle do this?
Assumed, you always have 6 consequent digits at the beginning, you could do something like this (in pre 10gR2 you have to use [0-9] instead of \d)
SQL> with t as (
2 select '123456def' s from dual union all
3 select '123490def879' from dual
4 )
5 select s,regexp_replace(s,'^(\d{4})(\d\d).*','\2') r
6 from t;
S R -------------------- -------- 123456def 56 123490def879 90
Best regards
Maxim Received on Thu Feb 04 2010 - 01:28:10 CST