DB2:xmlparse / cursor没有结果集

时间:2012-09-07 23:20:28

标签: xml stored-procedures db2

Techies-- 即使我知道我有2行,1在000020上有一个EMPNO匹配而在000030上有另一个,我得到一个空的结果集。有什么想法吗?

这是电话:

CALL DB2INST1.EMP_MULTIPLE_XML(XMLPARSE(
    DOCUMENT '<EMPLOYEE><EMPNO>000020</EMPNO><EMPNO>000030</EMPNO></EMPLOYEE>'));

这是改变的sproc:

   BEGIN

   CREATE PROCEDURE DB2INST1.EMP_MULTIPLE_XML (IN DOC XML)
   DYNAMIC RESULT SETS 1
   READS SQL DATA
   LANGUAGE SQL SPECIFIC EMP_MULTIPLE_XML

   DECLARE CSR1 CURSOR WITH RETURN FOR
    SELECT emp.EMPNO,
           emp.FIRSTNME,
           emp.LASTNAME,
           emp.WORKDEPT
     FROM DB2INST1.EMPLOYEE emp
     WHERE emp.EMPNO IN
      (SELECT X.EMPNO FROM
        XMLTABLE('$d/EMPLOYEE/EMPNO' PASSING DOC AS "d" COLUMNS EMPNO CHAR(6) PATH 'EMPNO') AS X);

 OPEN CSR1;
 END

2 个答案:

答案 0 :(得分:1)

考虑到proc正在将结果集传递出过程,FETCH似乎没有必要。尝试删除FETCH及其后的所有内容(最终END除外)。

'$d/employee'调用中的XMLTABLE参数不正确,因为您希望每次'$d/employee/empno'出现一行表格输出,而不是'$d/employee'。这就是造成 item(),item()+

错误的原因

此proc是一个独立的示例,展示了如何通过XML文档参数实现传递一组输入值的目标:

CREATE OR REPLACE PROCEDURE test.INPUT_MULTIPLE_XML (IN DOC XML)
DYNAMIC RESULT SETS 1
LANGUAGE SQL
SPECIFIC INPUT_MULTIPLE_XML

BEGIN

DECLARE CSR1 CURSOR WITH RETURN FOR

  select t.type,
         t.tabschema,
         t.tabname
   from syscat.tables t,  
   XMLTABLE('$d/tables/tabname' PASSING DOC AS "d" 
            COLUMNS "TABNAME" VARCHAR(128) PATH '.'
   ) AS X
   WHERE X.tabname = t.tabname
;

  OPEN CSR1;

END

答案 1 :(得分:0)

对于那些跟在我后面的线程的人来说,这里有一些有效的方法:

  CREATE OR REPLACE PROCEDURE test.INPUT_MULTIPLE_XML (IN DOC XML) 
  DYNAMIC RESULT SETS 1  
  LANGUAGE SQL SPECIFIC INPUT_MULTIPLE_XML  
  BEGIN  
     DECLARE CSR1 CURSOR WITH RETURN FOR    
        select t.type,          
               t.tabschema,          
               t.tabname    
         from syscat.tables t,      
          XMLTABLE('$d/tables/tabname' PASSING DOC AS "d" 
          COLUMNS "TABNAME" VARCHAR(128) PATH '.'    ) AS X   
           WHERE X.tabname = t.tabname ;    

  OPEN CSR1;  
  END