Oracle解释xml文档存入数据库



create or replace procedure add_to_stockmarket
(fileName IN varchar2,recordName IN varchar2)
as
  document xmldom.DOMDocument;--声明文档对象模型
  subelement xmldom.DOMElement;--声明元素类型
  nodelistStock xmldom.DOMNodeList;
  nodelistStockChild xmldom.DOMNodeList;
  stock_code char(6);--stock字段
  stock_name varchar2(30);--stockname字段
  stock_shortname varchar(30);--stockshortname字段
  recordCountOuter number;--存储xml文档中stock元素的个数

  begin
       document:=xmlparser.parse(fileName);--解析xml文档
       subelement:=xmldom.getDocumentElement(document);--获得根元素
       nodelistStock:=xmldom.getElementsByTagName(subelement,recordName);
       recordCountOuter:=xmldom.getLength(nodelistStock);
       for outerCycle in 0..recordCountOuter-1 loop
           nodelistStockChild:=xmldom.getChildNodes(xmldom.item(nodelistStock,outerCycle));
           stock_code:=xmldom.getNodeValue(xmldom.getFirstChild(xmldom.item(nodelistStockChild,0)));
           stock_name:=xmldom.getNodeValue(xmldom.getFirstChild(xmldom.item(nodelistStockChild,1)));
           stock_shortname:=xmldom.getNodeValue(xmldom.getFirstChild(xmldom.item(nodelistStockChild,2)));
           insert into stockmarket values(stock_code,stock_name,stock_shortname);
       end loop;
       commit;
  end;

你可能感兴趣的:(oracle,xml)