【问题标题】:Generating XML with DBMS_XMLGEN even if resultset is empty即使结果集为空,也使用 DBMS_XMLGEN 生成 XML
【发布时间】:2019-04-15 14:32:15
【问题描述】:

我正在使用 DBMS_XMLGEN 从给定查询创建 XML。我使用 XSLT 格式化此 XML。

当结果集为空时遇到问题:DBMS_XMLGen.getXML 返回的 XML 为空(没有空的 XML 节点 - 只是一个 0 大小的 clob)。 我需要 XML 保留与 XSLT 中定义的结构相同的结构,但只需返回空的 XML 节点。

这是代码(lv_FinalQuery 和 lv_Clb_Xsl 在此之前计算)

       -- creating new context query
       lv_Vc2_location := 'DBMS_XMLGEN.newContext';
       lv_queryCtx := DBMS_XMLGen.newContext(lv_FinalQuery);

       -- Setting the xsl file with the query context
       lv_Vc2_location := 'DBMS_XMLGEN.setXSLT';
       DBMS_XMLGen.setXSLT(lv_queryCtx,lv_Clb_Xsl);

       -- Setting the rowset tag
       lv_Vc2_location := 'DBMS_XMLGEN.setRowsetTag';
       DBMS_XMLGen.setRowsetTag(lv_queryCtx, 'USER_LIST');

       -- Setting the row tag
       lv_Vc2_location := 'DBMS_XMLGEN.setRowTag';
       DBMS_XMLGen.setRowTag(lv_queryCtx, 'USER');

       -- Getting the xml
       lv_Vc2_location := 'DBMS_XMLGEN.getXML';
       p_XmlResult := DBMS_XMLGen.getXML(lv_queryCtx);

【问题讨论】:

  • 也许您可以尝试将 nvl() 添加到您的值中。例如,nvl(L_USER,'')
  • 谢谢,Ahamed,因为有很多列,所以工作量很大。

标签: xml oracle plsql


【解决方案1】:

如果 DBMS_XMLGen.getXML 的输出为空,我最终会简单地返回一个预构建的 XML:

   IF p_XmlResult IS NULL THEN
        p_XmlResult := '<USER_LIST>the rest of the XSLT structure is here...</USER_LIST>';
   END IF;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-25
    • 2014-08-15
    • 1970-01-01
    • 2017-03-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多