Java JPQL:将 varchar 转换为数字
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20196009/
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
JPQL: convert varchar to number
提问by user3032749
How can i convert varchar to number in JPQL ???
如何在 JPQL 中将 varchar 转换为数字???
I managed to do that in sql (Oracle) with this query:
我设法用这个查询在 sql (Oracle) 中做到了这一点:
SELECT Decode(Upper(column_name), Lower(column_name), To_Number(column_name), -1)
FROM table
I want to do this conversion with JPQL.
我想用 JPQL 进行这种转换。
Thanks for your help
谢谢你的帮助
回答by Paul Vargas
You can do the next:
您可以执行以下操作:
CAST(e.salary AS NUMERIC(10,2))
Additionally, you can try:
此外,您可以尝试:
FUNC('TO_NUMBER', e.areaCode)
,FUNC
allows for a database function to be call from JPQL.SQL('CAST(? AS CHAR(3))', e.areaCode)
,SQL
allows for the usage and integration of SQL within JPQL.
FUNC('TO_NUMBER', e.areaCode)
,FUNC
允许从 JPQL 调用数据库函数。SQL('CAST(? AS CHAR(3))', e.areaCode)
,SQL
允许在 JPQL 中使用和集成 SQL。