views:

57

answers:

2

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

+2  A: 

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>
N. Gasparotto
thanks :). that worked. one more doubt. if i have to replace replace multiple line? say I have <ABC>ABCD</ABC>in the table and i want to replace it with XYZ. I I tried update nnn set c1=replace(c1,'<ABC>ABCD</ABC>','XYZ');but it didnt updated any anything.i have new line in the column.any advice?
Hemant
I'm not sure to understand, it is working fine. Please, show us your try.
N. Gasparotto
in my xml i have mulitple lines and i want to replace them with some new value. is it possible?
Hemant
+2  A: 

"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.

APC
Thanks that Worked.:). thanks for pointing XML datatype I havent used it before but defined try.
Hemant