简体   繁体   English

选择查询日期的最大值

[英]select max of date with query

I want to select max of date in hibernate but I get this error: 我想在休眠状态下选择日期的最大值,但出现此错误:

java.sql.SQLSyntaxErrorException: ORA-00932: inconsistent datatypes: expected TIMESTAMP got NUMBER java.sql.SQLSyntaxErrorException:ORA-00932:数据类型不一致:预期的TIMESTAMP得到了NUMBER

The query is : 查询是:

select   coalesce(max (rc.dateTransactionReceipt),0  ) from MAMReceiptTransactions rc where   rc.mamItems.id =m.id ) as lastDateOfCharge

and the database is oracle. 数据库是oracle。 Type of this field in database is TIMESTAMP(6) 数据库中此字段的类型为TIMESTAMP(6)

Trying to get 0 when timestamp doesn't make sense apart from being syntactically incorrect (The datatypes of the coalesce parameters must be compatible). 在语法上不正确(时间戳参数的数据类型必须兼容)之外,尝试使时间戳无意义时尝试获取0 Null itself sounds reasonable. 空本身听起来很合理。

select max(rc.dateTransaction) from your_table rc

If you want to have a default timestamp returned, you can use that in the coalesce instead. 如果要返回默认时间戳,则可以在合并中使用它。 Perhaps you want current timestamp returned in case the above returns null. 也许您想返回当前时间戳,以防上述情况返回null。

select coalesce(max(rc.dateTransaction), systimestamp) from your_table rc;

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

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