replace - Oracle REGEXP_REPLACE help adding dashes to a number string -


can me write oracle regexp_replace statement add dashes number this...

5310009618390 5310-00-961-8390 

i'm thinking need regexp_replace maybe not, maybe replace witll work. have tried both , not gotten anywhere.

select replace(t.column, 5310009618390, '-') table t 

well first need able describe want understand how build expression. example, appears be: group 1st 4 numbers, next 2 numbers, next 3 numbers next 4 numbers. if accurate:

select regexp_replace('5310009618390', '(\d{4})(\d{2})(\d{3})(\d{4})', '\1-\2-\3-\4') dual; 

this expression "remembers" groups described above, displays them dashes in between.

it's important able describe want do, build expression. i.e. if rule group 1st 4 characters (instead of numbers) expression different, etc.

note example regexp_replace can expensive depending on size of dataset operating on. if rules simple, may faster chop using substr() , concatenate pieces, adding dashes melanie suggests (only use || concatenation not +).


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -