在oracle语法模式下,oracle查询在内存中的hsqldb中失败

时间:2015-02-27 01:58:38

标签: sql oracle compatibility hsqldb named-query

以下查询在hsqldb 2.3.2中失败,sql.syntax_ora = true 在Oracle 11中正常工作。
它是一个名为hibernate的查询,用于TestNG测试,用于内存中的hsqldb,而不是真正的Oracle。 错误消息是:java.sql.SQLSyntaxErrorException:意外令牌:需要ORDER:):line:16,指的是 row_number()over(按lastUpdateTime desc排序)区域:

select  
        id         as id1_9_0_,  
        version    as version2_9_0_,  
        lastUpdateTime as lastUpda7_9_0_,  
        eventType    as eventTyp3_9_0_,  
        clientJid    as clientJi4_9_0_,  
        topicName as topicNam5_9_0_,  
        attributes as attribut6_9_0_  
    from (select logEvents.id as id,  
                 logEvents.version as version,  
                 logEvents.lastUpdateTime as lastUpdateTime,  
                 logEvents.eventType as eventType,  
                 logEvents.clientJid as clientJid,  
                 logEvents.topicName as topicName,  
                 logEvents.attributes as attributes,  
                 row_number() over (order by lastUpdateTime desc) rn    from xyz_logEvent logEvents)  
    where rn between 1 and 4 order by rn;  

1 个答案:

答案 0 :(得分:0)

HSQLDB并不支持所有可能的SQL语法。 row_number() over (order by ...)row_number() over ()时不支持(select logEvents.id as id, logEvents.version as version, logEvents.lastUpdateTime as lastUpdateTime, logEvents.eventType as eventType, logEvents.clientJid as clientJid, logEvents.topicName as topicName, logEvents.attributes as attributes, row_number() over () rn from xyz_logEvent logEvents order by lastUpdateTime limit 4)

替代方案可能如下所示:

{{1}}