xmltype.getClobVal:ORA-06502:PL / SQL:数字或值错误

时间:2014-04-28 11:04:19

标签: oracle oracle10g xmltype ora-06502

我的目标是通过Oracle 10g创建一个xml文件,我使用库dbms_xmldom来实现这一目标。 当我尝试通过getClobVal函数检索在XMLType中创建的clob时,服务器显示:

  

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

我的计划:

DECLARE
   l_xmltype XMLTYPE;
   l_domdoc dbms_xmldom.DOMDocument;
   l_root_node dbms_xmldom.DOMNode;
   l_reunion_element dbms_xmldom.DOMElement;
   l_reunions_node dbms_xmldom.DOMNode;
   l_r_element dbms_xmldom.DOMElement;
   l_r_node dbms_xmldom.DOMNode;
   l_reunion_element dbms_xmldom.DOMElement;
   l_reunion_node dbms_xmldom.DOMNode;
   l_course_element dbms_xmldom.DOMElement;
   l_course_node dbms_xmldom.DOMNode;
   l_eng_element  DBMS_XMLDOM.DOMELEMENT;
   l_eng_node DBMS_XMLDOM.DOMNODE;
   l_tp_element  DBMS_XMLDOM.DOMELEMENT;
   l_tp_node DBMS_XMLDOM.DOMNODE;

BEGIN
   -- Create an empty XML document
   l_domdoc := dbms_xmldom.newDomDocument;

   -- Create a root node
   l_root_node := dbms_xmldom.makeNode(l_domdoc);

   -- Create a new node Departments and add it to the root node
   --l_reunion_element := 
   l_reunions_node := dbms_xmldom.appendChild(l_root_node,dbms_xmldom.makeNode(dbms_xmldom.createElement(l_domdoc, 'donnees_reference_externes' )));
    -- réunion 
   FOR re IN ( select rc.identifiant, nvl(rc.date_report, RC.DATE_REUNION) date_reunion from reunion_course rc where date_reunion = '24/01/2014' )
   LOOP

        l_r_element := dbms_xmldom.createElement(l_domdoc, 'grep' );
      dbms_xmldom.setAttribute(l_r_element, 'ID', re.identifiant);
      dbms_xmldom.setAttribute(l_r_element, 'Date', re.date_reunion);
      l_r_node := dbms_xmldom.appendChild(l_reunions_node,dbms_xmldom.makeNode(l_r_element));

      -- course de la réunion selectionnée
      FOR rc in ( select * from course where id_reunion_course = re.identifiant ) 
      LOOP
      l_course_element := DBMS_XMLDOM.CREATEELEMENT(l_domdoc, 'ep');
      DBMS_XMLDOM.SETATTRIBUTE(l_course_element, 'ID', rc.identifiant);
      DBMS_XMLDOM.SETATTRIBUTE(l_course_element,'Prix', rc.nom_prix);
      l_course_node := DBMS_XMLDOM.APPENDCHILD(l_r_node, DBMS_XMLDOM.MAKENODE(l_course_element));

        FOR rg in ( select SIT.NUMERO_PMU, CH.NOM nom_cheval from situation_engagement_course sit, cheval ch where SIT.ID_CHEVAL = ch.identifiant and sit.id_course = rc.identifiant and SIT.CODE_ETAT = 'PARPR' ) 
        LOOP
            l_eng_element := DBMS_XMLDOM.CREATEELEMENT(l_domdoc, 'ap');
            DBMS_XMLDOM.SETATTRIBUTE(l_eng_element, 'NomCheval', rg.nom_cheval);
            DBMS_XMLDOM.SETATTRIBUTE(l_eng_element,'NPMU', rg.numero_pmu);
             l_eng_node := DBMS_XMLDOM.APPENDCHILD(l_course_node, DBMS_XMLDOM.MAKENODE(l_eng_element));

        END LOOP;  

      l_tp_element := DBMS_XMLDOM.CREATEELEMENT(l_domdoc, 'ofr');
      DBMS_XMLDOM.SETATTRIBUTE(l_tp_element, 'av_pg', rc.code_type_evenement_pari);
      DBMS_XMLDOM.SETATTRIBUTE(l_tp_element,'epba_ofr', 1);
      l_tp_node := DBMS_XMLDOM.APPENDCHILD(l_course_node, DBMS_XMLDOM.MAKENODE(l_tp_element));

      END LOOP;

   END LOOP;

   l_xmltype := dbms_xmldom.getXmlType(l_domdoc);
   dbms_xmldom.freeDocument(l_domdoc);

   dbms_output.put_line(l_xmltype.getClobVal);   -------------->   in this line ERROR Displays : ORA-06502: PL/SQL: numeric or value error ** 
END;

感谢。

2 个答案:

答案 0 :(得分:1)

<?php include "db_connect.php"; $new_joke_question = $_GET["newjoke"]; $new_joke_answer = $_GET["newanswer"]; $new_joke_question = $mysqli->real_escape_string($new_joke_question); $new_joke_answer = $mysqli->real_escape_string($new_joke_answer); // Search the database for the word chicken echo "<h2>Trying to add a new joke and answer: $new_joke_question $new_joke_answer </h2>"; if ($mysqli->connect_errno) { echo "Connection to MySQL failed: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; } echo $mysqli->host_info . "<br>"; $sql = "INSERT INTO Jokes_table (JokeID, Joke_question, Joke_answer) VALUES (' ', '$new_joke_question', '$new_joke_answer' )"; $result = $mysqli->query($sql); if ($mysqli->query($sql) === TRUE) { echo 'users entry saved successfully'; } else { echo 'Error: '. $mysqli->error .'<br>'; } include "search_all_jokes.php"; ?> <a href="index.php">Return to the main page</a> 存在一些局限性,在处理大数据时会引起问题:也就是说,大于32k的块确实无法通过这种方式打印,错误为ORA-06502。

如果您实际上不需要打印Clob,只需注释掉该行,就可以了。

否则,请看this StackOverflow post,它提供了一种基于过程的解决方案,该过程遍历Clob并一次打印出一个较小的块。

答案 1 :(得分:0)

l_xmltype.getClobVal ()

(我不确定这是否足够)

如果以编程方式调用getClobVal(),则必须在完成后显式释放此临时CLOB值。您可以通过调用PL / SQL方法DBMS_LOB.freeTemporary()

来完成此操作