declare
  new_xml xmltype; 
  res boolean;
begin

   select column_value into new_xml
   from xmltable('for $i in ora:view("PURCHASEORDER") 
                     where $i/PurchaseOrder/Reference = "SBELL-2002100912333601PDT"
                     return $i');
   
   select appendChildXML (new_xml,
                          '/PurchaseOrder/LineItems/LineItem[@ItemNumber="1"]',
                          xmltype('<Unit>Box</Unit>'))
          into new_xml from dual;

   select appendChildXML (new_xml,
                          '/PurchaseOrder/LineItems/LineItem[@ItemNumber="2"]',
                          xmltype('<Unit>Carton</Unit>'))
          into new_xml from dual;

   select appendChildXML (new_xml,
                          '/PurchaseOrder/LineItems/LineItem[@ItemNumber="3"]',
                          xmltype('<Unit>Case</Unit>'))
          into new_xml from dual;
          
   select updateXML (new_xml,
                     '/PurchaseOrder/Reference/text()',
                     'SBELL-2002100912333601PDT-V2')
          into new_xml from dual;

   insert into PURCHASEORDER values new_xml;
  
  commit;

end;
/
