我需要比较SELECT查询中的日期和时间戳。通常,大多数其他数据库平台(MySQL,MSSQL,Oracle等)都支持此功能,但在Derby中会引发以下错误:
Caused by: java.sql.SQLSyntaxErrorException: Comparisons between 'DATE' and 'TIMESTAMP' are not supported. Types must be comparable. String types must also have matching collation. If collation does not match, a possible solution is to cast operands to force them to the default collation (e.g. SELECT tablename FROM sys.systables WHERE CAST(tablename AS VARCHAR(128)) = 'T1')
我不想使用CAST,因为我无法更改SQL查询。这是Derby的bug,将在某个时间得到修复吗?我当前正在使用Derby 10.8.2.2。
谢谢!
最佳答案
如果您是从Java程序进行连接,则可以使用各种getxxx()方法来获取时间戳的特定部分(这些方法实际上是从Java.util.date继承的)
参见文档http://docs.oracle.com/javase/7/docs/api/java/util/Date.html
并检查getDate(),getDay(),getHour()...的方法
关于derby - 比较Derby中的时间戳和日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11017780/