简体   繁体   English

将以整数形式输入的参数转换为JasperReports中的字符串

[英]Convert a parameter entered as an integer to a string in JasperReports

I have a JRXML file that I use to generate a report built on a massive SQL query for an Oracle database. 我有一个JRXML文件,可用来生成基于Oracle数据库的大型SQL查询生成的报告。 I have entered a parameter to the report that gets filled as an Integer. 我在报表中输入了一个参数,该参数被填充为整数。 However, I would also like to reference this parameter as a String at a different point in the query. 但是,我也想在查询的不同点将此参数作为String引用。

Is there a way I can convert the parameter from an Integer to a String within the organization of JasperReports or do I have to create a separate parameter to fill each time the report is generated? 是否可以在JasperReports组织中将参数从Integer转换为String,还是必须创建一个单独的参数来填充每次生成报告的方法?

Solution found. 找到解决方案。 I simply changed the parameter type from integer to string as it was entered. 输入时,我只是将参数类型从整数更改为字符串。 Oracle can evaluate the string as a number and (when the parameter is within single quotes) can evaluate the string as a string as long as a bang (!) is used (eg $P!{VARIABLE}) Oracle可以将字符串评估为数字,并且(如果参数在单引号内)可以将字符串评估为字符串,只要使用了bang(!)(例如$ P!{VARIABLE})即可。

Can you not cast it within your query? 您不能在查询中使用它吗? Eg using TO_CHAR in Oracle, or ::text in PostgreSQL or the equivalent in your database (you do not specify). 例如,在Oracle中使用TO_CHAR,在PostgreSQL中使用:: text或数据库中的等效文本(未指定)。

To convert integer into string in jasper report you can use below 要在jasper report中将整数转换为字符串,可以在下面使用

($F{roomNumber}).toString()

It works. 有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM