Question

I have a table having one clob column which has XML data in it. Say I want to replace XYZ with ABC in the clob column. Is it possible using sqlplus?

Was it helpful?

Solution

"i have new line in the column. any advice?"

Newlines are characters; if you want to amend text which contains them you need to include them in the search string. You can do this using the CHR() which takes an ASCII value as an argument. The precise codes you need to include vary according to OS. Because I ran this example on MS Windows I needed to pass both linefeed (ASCII=10) and carriage return (ASCII=13).

SQL> select * from t42
  2  /

TXT
--------------------------------------------------------------------------------
<ABC> ABCD
  </ABC>


SQL>  update t42 set txt=replace(txt,'ABCD'||chr(10)||chr(13), 'APC woz here')
  2  /

1 row updated.

SQL> select * from t42
  2  /

TXT
--------------------------------------------------------------------------------
<ABC> APC woz here </ABC>

SQL>

Incidentally, if you are storing XML text it might be worthwhile using the XMLType datatype for the column instead of CLOB. It comes with a lot of useful functionality.

OTHER TIPS

Why not try it ?

SQL> create table nnn(c1 clob);

Table created.

SQL> insert into nnn values ('text ABC end');

1 row created.

SQL> select * from nnn;

C1
-------------------------------------------------
text ABC end

SQL> update nnn set c1=replace(c1,'ABC','XYZ');

1 row updated.

SQL> select * from nnn;

C1
-------------------------------------------------
text XYZ end

SQL>

Yes, it's possible with one REPLACE() function. Try:

update nnn set c1 = REPLACE(c1,'ABC>','XYZ>')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top