You can search a pattern and format the result.

Hello
I seek a function that search sequences and formats the output 1-way.
I tried to do this with regular expressions, but could not succeed.

My look of entry (projects codes) like this: EL10000, E10010RR, E10020ER.

Project codes get a different format in the new year:

EL10000 becomes 10000L 009 or EL patternwise ~ becomes ~ L009 where ~ is a number (10)
E ~ RR becomes ~ R009 where ~ is a number (10)
E ~ ER becomes ~ SBC9 where ~ is a number (10)

Is this possible with regexp_replace in 1 statement or just need I build a function?

Thanks in advance
Auke Quist

There is probably a better way...

with x as
(select 'EL10000' proj from dual union all
 select 'E10010RR' from dual union all
 select 'E10020ER' from dual
)
 -- End of Sample data
select proj
     , case
         when proj like 'EL%'
         then  substr (proj, 3)||'L009'
         when proj like 'E%RR'
         then regexp_substr (proj, '[[:digit:]]+')||'R009'
         when proj like 'E%ER'
         then regexp_substr (proj, '[[:digit:]]+')||'SBC9'
      end new_proj
  from x

Tags: Database

Similar Questions

Maybe you are looking for