English 中文(简体)
Converting Oracle date arithmetic to 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.
最佳回答

HSQLDB 2.0 (released in 2010) supports the syntax.

SELECT o 
FROM Offer o 
WHERE nowTime 
  BETWEEN o.startDate AND o.startDate + 7 DAY

It also suppports

o.startdate + INTERVAL  7  DAY

Update:

In ORA compatibility mode introduced since HSQLDB 2.2, the expression o.startDate + 7 is also supported.

问题回答

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:

CREATE TABLE OFFER (ID INTEGER, STARTDATE DATE);
INSERT INTO OFFER (ID, STARTDATE) VALUES (1, DATE  2009-01-01 );
SELECT ID, STARTDATE, STARTDATE + INTERVAL  7  DAY FROM OFFER;

In both environments I get the results showing the first and the eighth of January.

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.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签