1、创建目录-- Create directory
create or replace directory XML_PATH as 'D:\AAA';
2、导出XML
create or replace procedure cllx_db2xml is doc xmldom.DOMDocument; ret xmldom.DOMNode; rootnode xmldom.DOMNode; xmlfile varchar2(100) := 'XML_PATH'||'\'||'cllx.xml'; cursor cur_cllx is select * from code where dmlb='1'; procedure addcllx(doc xmldom.DOMDocument,parentnode xmldom.DOMNode,dmz varchar2,dmsm varchar2) is cllxelem xmldom.DOMElement; cllxnode xmldom.DOMNode; itemelem xmldom.DOMElement; itemnode xmldom.DOMNode; text xmldom.DOMText; begin cllxelem := xmldom.createElement(doc,'dmxx'); cllxnode := xmldom.appendChild(parentnode,xmldom.makeNode(cllxelem)); itemelem := xmldom.createElement(doc,'dmz'); itemnode := xmldom.appendChild(cllxnode,xmldom.makeNode(itemelem)); text := xmldom.createTextNode(doc,dmz); itemnode := xmldom.appendChild(itemnode,xmldom.makeNode(text)); itemelem := xmldom.createElement(doc,'dmms'); itemnode := xmldom.appendChild(cllxnode,xmldom.makeNode(itemelem)); text := xmldom.createTextNode(doc,dmsm); itemnode := xmldom.appendChild(itemnode,xmldom.makeNode(text)); end addcllx; begin --创建一个新的文档对象 doc := xmldom.newDOMDocument; --根标签 rootnode := xmldom.makeNode(xmldom.createElement(doc,'jtfs')); ret := xmldom.appendChild(xmldom.makeNode(doc),rootnode); --遍历结果集 for v_row in cur_cllx loop addcllx(doc,ret,v_row.dmz,v_row.dmsm1); end loop; --设置版本号 xmldom.setVersion(doc,'1.0'); --把数据写入文件 xmldom.writeToFile(doc,xmlfile,'GBK'); --释放文档对象资源 xmldom.freeDocument(doc); end cllx_db2xml;