Is there a portable way to have “SELECT FIRST 10 * FROM T” semantic?

前端 未结 5 1349
死守一世寂寞
死守一世寂寞 2020-12-10 03:56

I want to read data in blocks of say 10k records from a database.

I found Result limits on wikipedia and it seems obvious that this can\'t done with sql in a portabl

5条回答
  •  青春惊慌失措
    2020-12-10 04:20

    If you want a portable way, you need to move up an abstraction layer, as there's no portable SQL way(not one that databases actually implement anyways) - and use ORM mappers like e.g hibernate.

    If you do need raw JDBC, you'll have to write specific SQL for eache specific database - which is often the case anyway as writing 100% portabl SQL is pretty hard in all but the trivial cases.

    The last resort is to run the query without any restrictions and just iterate over the 10 first results you get back - though this doesn't leverage the database capabilities and would be quite bad if your query results in many rows.

提交回复
热议问题