In our oracle db, there is a varchar column in which I want to replace all linefeeds (or carriage return/linefeeds) with "<br/>" (we're changing a textfield for use with a html editor). I looked up the REGEXP_REPLACE function of oracle which seems like it should be able to do that, but I can't seem to get the reg exp right...I tried
REGEXP_REPLACE(column_name, '(\r?\n)', '<br/>')
but I see no replacement being done. I think I got the basic syntax right as I can replace normal characters. I also tried writing the linefeed in different ways, like \\n or \x0a but these don't seem right either. Has anyone done this before perhaps and can tell me the right syntax, documentation I saw says it should be \r and \n but these simply don't work for me
Joined: Feb 02, 2009
I solved this differently now, using the normal REPLACE function of oracle:
update <table> set <column>=REPLACE(<column>, CHR(13)) where ...;
update <table> set <column>=REPLACE(<column>, CHR(10), '<br/>') where ...;
First, carriage return characters are removed. Then, linefeed characters are replaced by <br/>. This seems to work fine.
Still interested if anyone knows the correct syntax for a regular expression tho.