向xml添加数据会产生错误

时间:2015-03-06 19:24:20

标签: oracle

我正在使用一个plsql块,它具有以下代码,并且在if条件下给我一个错误。

错误: - ORA-31020:不允许该操作,原因:pl / sql DOM句柄无效

PROCEDURE add_to_xml(
    p_doc         IN OUT dbms_xmldom.domdocument ,
    p_node_parent IN dbms_xmldom.domnode ,
    p_table       IN xml_tabtype )
IS
  k_routine CONSTANT VARCHAR2(255) := gk_package||'add_to_xml';
  l_stmt    VARCHAR2(512);
  l_node_child dbms_xmldom.domnode;
  l_txt_node dbms_xmldom.domnode;
  l_elem dbms_xmldom.domelement;
BEGIN
  FOR i IN p_table.first..p_table.last
  LOOP
    l_elem              := dbms_xmldom.createelement( doc => p_doc , tagname => p_table( i ).tagname );
    l_node_child        := dbms_XMLDom.appendChild( p_node_parent , dbms_XMLDom.makeNode( l_elem ));
    IF p_table( i ).val IS NOT NULL THEN
      l_txt_node        := dbms_xmldom.appendchild( l_node_child , dbms_xmldom.makenode( dbms_xmldom.createtextnode( p_doc , p_table( i ).val )));
    END IF;
  END LOOP;
EXCEPTION
WHEN OTHERS THEN
  dbms_output.put_line('error in add_to_xml'||SQLCODE||sqlerrm);
END add_to_xml;

你能问一下这个错误弹出的原因吗?

我已经调试了这个,之前如果条件我有通过这个过程的所有相关数据。我的数据库版本是11。

调用代码是

declare
t_xml_tab                      xxcu_hr_interface.xml_tabtype;
l_doc                          dbms_xmldom.domdocument;
      l_top_node                     dbms_xmldom.domnode;
      l_node_top_detail              dbms_xmldom.domnode;
      l_node_assignment_change       dbms_xmldom.domnode;
      l_node_hdr_assignment_hdr      dbms_xmldom.domnode;

begin
t_xml_tab.delete;
           t_xml_tab(t_xml_tab.count + 1).tagname := 'OperasjonsID';
           t_xml_tab(t_xml_tab.count).val := 'U'; --Defect 1047
           t_xml_tab(t_xml_tab.count + 1).tagname := 'BusinessGroupID';
           t_xml_tab(t_xml_tab.count).val := 101;
           t_xml_tab(t_xml_tab.count + 1).tagname := 'FirmaID';
           t_xml_tab(t_xml_tab.count).val := 984661185;
           t_xml_tab(t_xml_tab.count + 1).tagname := 'AnsattNr';
           t_xml_tab(t_xml_tab.count).val := 52022;
           t_xml_tab(t_xml_tab.count + 1).tagname := 'StartDato';
           t_xml_tab(t_xml_tab.count).val := xxcu_hr_common.conv_date('18-AUG-75');
           t_xml_tab(t_xml_tab.count + 1).tagname := 'SluttDato';
           t_xml_tab(t_xml_tab.count).val := xxcu_hr_common.conv_date('31-DEC-12');
           t_xml_tab(t_xml_tab.count + 1).tagname := 'Primaer';
           t_xml_tab(t_xml_tab.count).val := 'J';
           t_xml_tab(t_xml_tab.count + 1).tagname := 'IntegrationKey1';
           t_xml_tab(t_xml_tab.count).val := 11933;
           t_xml_tab(t_xml_tab.count + 1).tagname := 'IntegrationKey2';
           t_xml_tab(t_xml_tab.count).val := 123;
           t_xml_tab(t_xml_tab.count + 1).tagname := 'PersonKategori';
           t_xml_tab(t_xml_tab.count).val := 1;

           dbms_output.put_line('3.7');

           ---dbms_output.put_line('3.7.1 t_xml_tab'||t_xml_tab(t_xml_tab.count + 1).tagname );

           xxcu_hr_interface.add_to_xml(p_doc         => l_doc,
                                        p_node_parent => l_node_hdr_assignment_hdr,
                                        p_table       => t_xml_tab);

 --dbms_output.put_line(l_doc);
exception
when others then
dbms_output.put_line('The error is :'||sqlcode||sqlerrm);
end;

1 个答案:

答案 0 :(得分:0)

您需要先通过createdocument函数创建文档,然后再将其传递到您的过程中。

DBMS_XMLDOM Documentation

相关问题