Dev G Dev G - 1 year ago 151
SQL Question

Oracle: Replace first character to other character

I have a table in oracle in which we have one column having data as

, means first alphabet always
and followed by numeric. I want to replace all such instances with
that will become

So if already there is a value called BH45678 in that column don't update.

Only where find B followed by numeric need updates.

vkp vkp
Answer Source

Get the rows which have B followed by digits using regexp_like. Then use replace to replace B with BH for those rows.

select replace(col,'B','BH')
from tablename
where regexp_like(col,'^B\d+$')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download