如何使用JPA查询对列值进行舍入? [英] How can I round a column value with a JPA query?
本文介绍了如何使用JPA查询对列值进行舍入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将存储在数据库中的数字作为浮点数进行比较(这必须支持多个数据库,并且我无法控制它的存储方式),但是当然,平等只会让你
select * from x where round(col) ,2)=?;
不幸的是,我似乎无法在JPQL中找到这样做的方法。有没有什么办法可以实现这一点(不需要更改数据库)?解决方案
p>
I need to compare for equality on a number stored in the database as a floating point number (this has to support multiple databases and I haven't got any control over how it's stored), but of course equality will only get you so far with an approximated value, so I need to round the column value like this:
select * from x where round(col, 2) = ?;
Unfortunately I can't seem to find a way of doing that in JPQL. Is there any way to achieve this (without changing the database)?
解决方案
I have two ideas to solve this problem:
make a between query
use a native query
这篇关于如何使用JPA查询对列值进行舍入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文