0

As I'm new to oracle, not sure how to handle the pagination logic.

I need a query that returns the results based on the start vale and the limit value.

See the below resultset

id   name
1    abc
2    def
3    ghi
4    jkl
5    qqq
6    www
7    eee
8    ttt
9    yyy
10   uuu
11   iii
12   ppp
13   aaa 
14   sss
15   ddd
16   fff
17   ggg
18   hhh
19   jjj
20   kkk

For suppose if I give the values start value = 0 and limit = 5 then it should return the below records

id name
1  abc
2  def
3  ghi
4  jkl
5  qqq

if start value = 5 and limit = 15 , then I should return the below result

id name
5  qqq
6  www
7  eee
8  rrr
9  ttt
10 yyy
11 uuu
12 iii
13 ooo
14 ppp
15 ddd
16 fff
17 ggg
18 hhh
19 jjj

Please help me with the query Please let me know if anything.

Thanks

sstan
  • 35,425
  • 6
  • 48
  • 66
Naresh
  • 81
  • 8
  • Did you try googling "oracle pagination"? – sstan Jun 13 '16 at 19:42
  • 1
    Possible duplicate of [Best practice for pagination in Oracle?](http://stackoverflow.com/questions/13738181/best-practice-for-pagination-in-oracle), or also [Paging with Oracle](http://stackoverflow.com/questions/241622/paging-with-oracle). – sstan Jun 13 '16 at 19:43
  • Yeah, I need a query with start value and limit conditions. The links which you provided are with page number and page size/ beginning and end value. – Naresh Jun 13 '16 at 20:15
  • That's only one of the answers. If you take the time to read the threads, you'll see it has all the info you need. – sstan Jun 13 '16 at 20:51

1 Answers1

0

Probably best to use bind variables for this. If you are not familiar with Oracle bind variables, spend 15 minutes reading about them, they are super helpful.

select id, name 
from   your_table
where  id between :start_value and :start_value + :limit_value - 1;