ORACLE xmltype 遍历

DECLARE 
  var       XMLType; 
  doc       DBMS_XMLDOM.DOMDocument; 
  ndoc      DBMS_XMLDOM.DOMNode; 
  docelem   DBMS_XMLDOM.DOMElement;
  nodelist  DBMS_XMLDOM.DOMNodelist;
  node      DBMS_XMLDOM.DOMNode; 
  buf       VARCHAR2(2000);
  v_size    number;

begin 
select PKGPRINTCODES into var   from event_processatlocation where EPL_SYSCODE=142;
  doc    := DBMS_XMLDOM.newDOMDocument(var); 
  ndoc    := DBMS_XMLDOM.makeNode(doc);
  DBMS_XMLDOM.writeToBuffer(ndoc, buf);
  DBMS_OUTPUT.put_line('Before:'||buf);
  
  docelem := DBMS_XMLDOM.getDocumentElement(doc);
  nodelist := DBMS_XMLDOM.getElementsByTagName(docelem, 'PKG_PRINTCODE');

  v_size:=DBMS_XMLDOM.GETLENGTH(nodelist);

  for v in 1..v_size loop
     node := dbms_xmldom.GETFIRSTCHILD(DBMS_XMLDOM.item(nodelist, v-1));
     DBMS_OUTPUT.put_line('aa'||DBMS_XMLDOM.GETNODEVALUE(node));
  end loop;
end;

 

你可能感兴趣的:(oracle)