oracle 在 JasperReports 中将作为整数输入的参数转换为字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1029635/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 18:26:49  来源:igfitidea点击:

Convert a parameter entered as an integer to a string in JasperReports

javasqloraclejasper-reports

提问by leadingzero

I have a JRXML file that I use to generate a report built on a massive SQL query for an Oracle database. 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.

我有一个 JRXML 文件,用于生成基于 Oracle 数据库的大量 SQL 查询的报告。我在报告中输入了一个参数,该参数被填充为整数。但是,我还想在查询的不同点将此参数作为字符串引用。

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 组织内将参数从整数转换为字符串,或者我是否必须在每次生成报告时创建一个单独的参数来填充?

采纳答案by leadingzero

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 (e.g. $P!{VARIABLE})

找到解决方案。我只是在输入时将参数类型从整数更改为字符串。Oracle 可以将字符串计算为数字,并且(当参数在单引号内时)可以将字符串计算为字符串,只要使用了 bang (!)(例如 $P!{VARIABLE})

回答by Vineet Jain

To convert integer into string in jasper report you can use below

要将整数转换为 jasper 报告中的字符串,您可以在下面使用

($F{roomNumber}).toString()

It works.

有用。

回答by the.jxc

Can you not cast it within your query? E.g using TO_CHAR in Oracle, or ::text in PostgreSQL or the equivalent in your database (you do not specify).

你不能在你的查询中投射它吗?例如,在 Oracle 中使用 TO_CHAR,或在 PostgreSQL 中使用 ::text 或数据库中的等效项(您未指定)。