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

Inserte xmltype en xmltype en el lugar especificado [PL/SQL]

Puede usar el mencionado appendChildXML , como aquí:

declare
  v_xml  xmltype := xmltype('<ord>
                               <head>
                                 <ord_code>123</ord_code>
                                 <ord_date>01-01-2015</ord_date>
                               </head>
                             </ord>');
  v_xml2 xmltype:= xmltype('<pos>
                              <pos_code>456</pos_code>
                              <pos_desc>description</pos_desc>
                            </pos>');
  v_output xmltype;
begin
  select appendChildXML(v_xml, 'ord', v_xml2) 
    into v_output from dual;

  -- output result
  dbms_output.put_line( substr( v_output.getclobval(), 1, 1000 ) );
end;

Salida:

<ord>
  <head>
    <ord_code>123</ord_code>
    <ord_date>01-01-2015</ord_date>
  </head>
  <pos>
    <pos_code>456</pos_code>
    <pos_desc>description</pos_desc>
  </pos>
</ord>