mybatis / mybatis-dynamic-sql

SQL DSL (Domain Specific Language) for Kotlin and Java. Supports rendering for MyBatis or Spring JDBC Templates
http://www.mybatis.org/mybatis-dynamic-sql/docs/introduction.html
Apache License 2.0
1.09k stars 212 forks source link

[Feature Request]: How to do paging querys for SqlSever or Oracle? #492

Closed lasyka closed 2 years ago

lasyka commented 2 years ago

Is this support paging querys for SqlSever or Oracle? the limit,offset is not supported by these databases。

jeffgbutler commented 2 years ago

Both Oracle and SQL Server support offset and fetch first like this:

select(foo).from(bar).offset(4).fetchFirst(4).rowsOnly()

lasyka commented 2 years ago

Both Oracle and SQL Server support offset and fetch first like this:

select(foo).from(bar).offset(4).fetchFirst(4).rowsOnly()

Thanks for your replay. But this failed for me:
Code:
measureTDynMapper.select(c->c.where(upload,isNotEqualTo("1")).offset(4).fetchFirst(4).rowsOnly());
And the sql from above code is like this:

SELECT
    * 
FROM
    TABLEA
WHERE
    upload <> 1 offset 4 ROWS FETCH FIRST 4 ROWS ONLY

This sql will failed execute in sqlserver 2012

[42000] [Microsoft][SQL Server Native Client 11.0][SQL Server]'offset' 附近有语法错误。 (102) [42000] [Microsoft][SQL Server Native Client 11.0][SQL Server]在 FETCH 语句中选项 FIRST 的用法无效。 (153)

jeffgbutler commented 2 years ago

You may need to add an order by expression in SQL Server. See the docs here:

https://docs.microsoft.com/en-us/previous-versions/sql/sql-server-2012/ms188385(v=sql.110)