Java DB2和Jasper报告中的合并问题

Java DB2和Jasper报告中的合并问题,java,sql,jasper-reports,db2,coalesce,Java,Sql,Jasper Reports,Db2,Coalesce,我有一个查询,其中我从通过子查询形成的表中取出一列的总和 这句话的意思是: select temp.mySum as MySum from (select sum(myColumn) from mySchema.myTable) temp; 但是,当temp.MySum为null时,我不希望MySum为null。相反,当temp.MySum为null时,我希望MySum携带字符串“value not available” 因此,我尝试以以下方式使用coalesce: select coales

我有一个查询,其中我从通过子查询形成的表中取出一列的总和

这句话的意思是:

select temp.mySum as MySum from (select sum(myColumn) from mySchema.myTable) temp;
但是,当temp.MySum为null时,我不希望MySum为null。相反,当temp.MySum为null时,我希望MySum携带字符串“value not available”

因此,我尝试以以下方式使用coalesce:

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.
此消息是由于以下第一个答案中提到的coalesce函数的参数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。我想在报告中显示“值不可用”

如何做到这一点


谢谢你的阅读

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

例如,下面的表显示了各种类型之间的兼容性,至少对于我使用的DB2(大型机),毫无疑问,iSeries和LUW变体也有类似的限制

您可以尝试类似于
coalesce(temp.mySum,0)
的方法,或者使用类似于
char()
的方法将第一个参数转换为字符串。这两个参数中的任何一个都可以工作,因为它们使两个参数兼容。

Yes,
COALESCE(CHAR(temp.mysum),'value not available')
将在DB2LUW上提供所需的结果