REPLACE, Executed On A CLOB Returned By XMLSERIALIZE( CONTENT Column AS CLOB), Returns NULL (Doc ID 1376531.1)

Last updated on FEBRUARY 08, 2017

Applies to:

Oracle Server - Standard Edition - Version 11.2.0.2 to 11.2.0.3 [Release 11.2]
Information in this document applies to any platform.

Symptoms


If a REPLACE is executed on a CLOB value, obtained running an XMLSERIALIZE( CONTENT column AS CLOB), then the result is always NULL.

The following code example shows this behavior:

create table x (xmlvalue xmltype);
insert into x values (xmltype('<A><B>C</B></A>'));
commit;
set serverout on
declare
  l_clob clob;
  l_vc2 varchar2(40);
  l_result clob;
  begin
  select xmlserialize (CONTENT xmlvalue AS CLOB), xmlserialize (CONTENT xmlvalue AS VARCHAR2(40))
  into l_clob, l_vc2
  from x;

  if l_clob = l_vc2 then dbms_output.put_line('Clob and Varchar2 are identical, but'); end if;

  l_result := REPLACE( l_clob, 'any');
  dbms_output.put_line('Replace on CLOB:
  ' || l_clob || '
  becomes
  |' || l_result || '|');
  l_result := REPLACE( l_vc2, 'any');
  dbms_output.put_line('
  Replace on Varchar2 :
  ' || l_vc2 || '
  becomes
  |' || l_result || '|');
end;
/

Ouptut:
Clob and Varchar2 are identical, but
Replace on CLOB:
<A>
<B>C</B>
</A>

becomes
||

Replace on Varchar2 :
<A>
<B>C</B>
</A>

becomes
|<A>
<B>C</B>
</A>
|

Cause

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms