gpt4 book ai didi

java - DB2 和 Jasper 报告中的 COALESCE 问题

转载 作者:行者123 更新时间:2023-12-02 07:47:53 25 4
gpt4 key购买 nike

我正在进行一个查询,其中我从通过子查询形成的表中提取列的总和。

行中的内容:

select temp.mySum as MySum from (select sum(myColumn) from mySchema.myTable) temp;

但是,当 temp.mySum 为 null 时,我不希望 MySum 为 null。相反,当 temp.mySum 为 null 时,我希望 MySum 携带字符串“值不可用”。

因此我尝试通过以下方式使用合并:

select coalesce(temp.mySum, 'value not available') as MySum from (select sum(myColumn) from mySchema.myTable) temp;

但是上面的查询抛出错误消息:

Message: The data type, length or value of argument "2" of routine "SYSIBM.COALESCE" is incorrect.

此消息是因为合并函数的参数 1 和 2 之间的数据类型不兼容,如下面第一个答案中所述。

但是,我直接在 Jasper 中使用此查询将值发送到 Excel 工作表报告:

hashmap.put("myQuery", this.myQuery);
JasperReport jasperReportOne = JasperCompileManager.compileReport(this.reportJRXML);
JasperPrint jasperPrintBranchCd = JasperFillManager.fillReport(jasperReportOne , hashmap, con);
jprintList.add(jasperPrintOne);
JRXlsExporter exporterXLS = new JRXlsExporter();
exporterXLS.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jprintList);
exporterXLS.exportReport();

在 Excel 工作表中,当值不可用时,我得到的值为 null。我想在报告中显示“值(value)不可用”。

如何实现这一目标?

感谢您的阅读!

最佳答案

合并的参数必须兼容。如果第一个是数字(例如 mySum 可能是)而第二个是字符串,则情况并非如此。

例如以下PubLib doco有一个表指示各种类型之间的兼容性,至少对于我使用的 DB2(大型机)来说是这样 - 毫无疑问,iSeries 和 LUW 变体也有类似的限制。

您可以尝试使用诸如 coalesce(temp.mySum, 0) 之类的方法,或者使用诸如 char() 之类的方法将第一个参数转换为字符串。其中任何一个都应该有效,因为它们使两个参数兼容。

关于java - DB2 和 Jasper 报告中的 COALESCE 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10583118/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com