在Oracle中访问存储为对象关系的XML对象的最佳方法是什么?

时间:2017-11-10 13:36:59

标签: xml oracle orm oracle12c

首先,我使用的是Oracle 12版本1

我需要在Oracle数据库中检索存储为对象关系的对象,但速度太慢 - 我正在使用Dom Documents这样做。

我正在使用的功能:

create or replace FUNCTION XML_myDistance(
  innXML XMLType,
  outXML XMLType
) RETURN number
IS
  total NUMBER := 0;
  docInn xmldom.DOMDocument;
  docOut xmldom.DOMDocument;
  nInn xmldom.DOMNode;
  nOut xmldom.DOMNode;
  nlInn xmldom.DOMNodeList;
  nlOut xmldom.DOMNodeList;
  len number;
BEGIN
--Converte os atributos xmltype para DOMDocuments.
docInn := dbms_xmldom.newDOMDocument(innXML);
docOut := dbms_xmldom.newDOMDocument(outXML);

nlInn := xmldom.getElementsByTagName(docInn, '*');
nlOut := xmldom.getElementsByTagName(docOut, '*');
len := xmldom.getLength(nlInn);

for i in 1..len-1 loop
        nInn := xmldom.item(nlInn, i);
        nOut := xmldom.item(nlOut, i);
        total := total + ABS(xmldom.getNodeValue(DBMS_XMLDOM.getFirstChild(nInn)) - xmldom.getNodeValue(DBMS_XMLDOM.getFirstChild(nOut)));
end loop;

DBMS_XMLDOM.freeDocument(docInn);
DBMS_XMLDOM.freeDocument(docOut);

RETURN total;
END;
/

我也尝试了以下查询......但其性能更差......

create or replace FUNCTION myDistance(
  innXML XMLType,
  outXML XMLType
) RETURN number
IS
  total NUMBER;
BEGIN
  SELECT SUM( ABS(oFV.feature - iFV.feature) )
  INTO   total
  FROM   XMLTABLE(
           '//FeatureVector/feature'
           PASSING outXML
           COLUMNS rn       FOR ORDINALITY,
                   feature  NUMBER  PATH '.'
         ) oFV
         INNER JOIN
         XMLTABLE(
           '//FeatureVector/feature'
           PASSING innXML
           COLUMNS rn       FOR ORDINALITY,
                   feature  NUMBER  PATH '.'
         ) ifv
         ON ( oFV.rn = iFV.rn );

  RETURN total;
END;
/

是否有另一种方法可以在Oracle中访问存储为对象关系对象的XML数据?一个更有效率的。

0 个答案:

没有答案