将 Oracle 日期算术转换为在 HSQLDB 中工作
我正在尝试使用 hsqldb 和 dbunit 对 Oracle 支持的数据库进行现场测试,但遇到了障碍。
问题在于以下 EJB-QL(稍微简化了一点):
SELECT o
FROM Offer o
WHERE :nowTime
BETWEEN o.startDate AND o.startDate + 7
这似乎只适用于 Oracle 的 SQL 版本。
对我来说,将其转换为在 hsqldb 和 oracle 中工作的最简单方法是什么?假设将参数之间的两个更改为命名参数是一个非常困难的重构,所以我将倾向于提供更标准化的模拟的答案
o.startdate + 7
编辑: 经过更多研究后,Oracle 似乎将上面的代码片段转换为
o.startdate + INTERVAL '7' DAYwhich is apparently more standard, but doesn't work in HSQLDB.
I'm trying to spot-test an Oracle backed database with hsqldb and dbunit, but I've run into a snag.
The problem is with the following EJB-QL (simplified a bit):
SELECT o
FROM Offer o
WHERE :nowTime
BETWEEN o.startDate AND o.startDate + 7
This seems to only work in Oracle's version of SQL.
What's the easiest way for me to convert this to work in both hsqldb and oracle? Assume that changing the two between arguments to named parameters is a very difficult refactor, so I'm going to favor answers that provides a more standardized analog to
o.startdate + 7
EDIT:
After doing some more research, it looks like Oracle converts the above snippet to
o.startdate + INTERVAL '7' DAY
which is apparently more standard, but doesn't work in HSQLDB.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
HSQLDB 2.0(2010年发布)支持该语法。
它还支持
更新:
在HSQLDB 2.2以来引入的ORA兼容模式中,还支持表达式
o.startDate + 7
。HSQLDB 2.0 (released in 2010) supports the syntax.
It also suppports
Update:
In ORA compatibility mode introduced since HSQLDB 2.2, the expression
o.startDate + 7
is also supported.你的方法似乎是正确的。我不知道你有什么问题。这是使用以下脚本在 Oracle 和 HSQLDB 中运行的:
在这两种环境中,我都得到显示 1 月 1 日和 8 日的结果。
Your methodology seems correct. I don't know what you're having trouble with. This is working in Oracle and HSQLDB using the script below:
In both environments I get the results showing the first and the eighth of January.
用于日期操作的 HSQLDB 语法与 Oracle 有很大不同。最好的机会是在 Oracle DB 中编写一个存储过程来模拟 HSQLDB 函数/过程的行为。
The HSQLDB syntax for date manipulation is quite different from Oracle. Your best chance is to write a stored procedure in the Oracle DB which simulates the behavior of the HSQLDB functions/procedures.