ORA-06502在使用DOMNode时的Oracle函数

时间:2018-01-23 18:50:11

标签: xml oracle dom plsql oracle12c

我正在尝试在Oracle 12c上执行plsql代码。

描述环境:

首先,注册XML架构。

BEGIN
-- Register the schema
DBMS_XMLSCHEMA.registerSchema('http://www.example.com/fvInteger.xsd',
'<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="FeatureVector">
<xs:complexType>
<xs:sequence>
<xs:element name="feature" type="xs:integer" minOccurs="64" maxOccurs="64"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>',
   TRUE, TRUE, FALSE);
END;
/

然后创建表

CREATE TABLE fv_XML_64 (
   id    NUMBER,
   fv  XMLTYPE)
   XMLTYPE complex_obj STORE AS OBJECT RELATIONAL
      XMLSCHEMA "http://www.example.com/fvInteger.xsd"
      ELEMENT "FeatureVector";

我收到错误:

  

SELECT mahalanobis_distance_XML((SELECT fv FROM fv_XML_64 c WHERE   c.id = 1000),(SELECT fv FROM fv_XML_64 c WHERE c.id = 988))FROM DUAL;   SELECT mahalanobis_distance_XML((SELECT fv FROM fv_XML_64 c WHERE   c.id = 1000),(SELECT fv FROM fv_XML_64 c WHERE c.id = 988))FROM DUAL          * ERRO na linha 1:ORA-06502:PL / SQL:erro numerico ou de valor ORA-06512:em“HIGIIA.MAHALANOBIS_DISTANCE_XML”,第50行

我正在尝试执行的功能:

create or replace FUNCTION mahalanobis_distance_xml(
  innXML XMLType,
  outXML XMLType
) RETURN number
IS
  total NUMBER := 0;
  docInn xmldom.DOMDocument;
  docOut xmldom.DOMDocument;
  nInn xmldom.DOMNode;
  nInn2 xmldom.DOMNode;
  nOut xmldom.DOMNode;
  aux NUMBER;
  max_d NUMBER :=0;
  nlInn xmldom.DOMNodeList;
  nlInn2 xmldom.DOMNodeList;
  nlOut xmldom.DOMNodeList;
  TYPE tbNumber IS TABLE OF NUMBER INDEX BY PLS_INTEGER;
  TYPE tbNumberMatrix IS TABLE OF tbNumber INDEX BY PLS_INTEGER;
  l INTEGER;
  l_out INTEGER;
  mA tbNumberMatrix;
  mD tbNumberMatrix;
  x_minus_y INTEGER_ARRAY := INTEGER_ARRAY();
BEGIN
--Converte os atributos xmltype para DOMDocuments.
docInn := dbms_xmldom.newDOMDocument(innXML);
docOut := dbms_xmldom.newDOMDocument(outXML);

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

IF l = l_out THEN 

        x_minus_y.extend(l) ;

        FOR i IN 1..l LOOP
            FOR j IN 1..l LOOP
                mA(i)(j) := 0;
                mD(i)(j) := 0;
            END LOOP;
        END LOOP;


        FOR i IN 1..l LOOP
            nInn := xmldom.item(nlInn, i);
                        nOut := xmldom.item(nlOut, i);
            x_minus_y(i)  := ABS(xmldom.getNodeValue(DBMS_XMLDOM.getFirstChild(nInn)) -  xmldom.getNodeValue(DBMS_XMLDOM.getFirstChild(nOut)));
            FOR j IN 1..l LOOP
                nInn2 := xmldom.item(nlInn, j);
                mD(i)(j) := ABS(xmldom.getNodeValue(DBMS_XMLDOM.getFirstChild(nInn2)) - xmldom.getNodeValue(DBMS_XMLDOM.getFirstChild(nOut)));

...

错误出现在代码的这一部分:

        FOR j IN 1..l LOOP
            nInn2 := xmldom.item(nlInn, j);
            mD(i)(j) := ABS(xmldom.getNodeValue(DBMS_XMLDOM.getFirstChild(nInn2)) - xmldom.getNodeValue(DBMS_XMLDOM.getFirstChild(nOut)));

有什么问题?

我在文档中得到了这个:

  

ORA-06502:PL / SQL:数字或值错误字符串

     

原因:算术,数字,字符串,转换或约束错误   发生了。例如,如果尝试,则会发生此错误   将值NULL赋给声明为NOT NULL的变量,或者如果是   尝试将大于99的整数分配给变量   宣布NUMBER(2)。

     

操作:更改数据,操作方式或声明方式   这样值就不会违反约束条件。

但是我无法找到所呈现功能的错误。

0 个答案:

没有答案