sql >> Base de Datos >  >> RDS >> Oracle

Problema XMLAGG con RTRIM

Debe agregar .getClobVal() a su resultado XMLType, antes del RTRIM.

XMLAGG funciona bien con grandes cantidades de datos. Y TRIM funciona bien con CLOB. Pero cuando los junta, Oracle intenta convertir XMLType en VARCHAR2 en lugar de CLOB.

Ejemplo:

create or replace function test_function return clob is
    v_clob clob;
begin
    v_clob := v_clob || lpad('a', 4000, 'a');
    v_clob := v_clob || lpad('b', 4000, 'b');
    return v_clob;
end;
/

--Works fine, returns an XMLType
select xmlagg(xmlelement("asdf", test_function)) from dual;

--Works fine, returns a CLOB
select trim(test_function) from dual;

--ORA-19011: Character string buffer too small
select trim(xmlagg(xmlelement("asdf", test_function))) from dual;

--Works
select trim(xmlagg(xmlelement("asdf", test_function)).getClobVal()) from dual;