• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

using rownum with union

 
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In order implement pagination on the front end, I need specific number(1-10, 11-20 ..) of rows to be returned from the db.

I know we can use constraints like
select * from table Where ROWNUM < 10

However I'm using multiple (4) joins in my sql query to fetch data from oracle 10g db.

How do i achieve this.
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
setMaxRows(int maxRows) on statement object
 
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to fetch for each page then you need to use ORDER BY and ROWNUM. Let's say I join 3 tables emp, dept, loc and I need n rows at a time.

The query would be


You need to bind the values for ROWNUM predicate.

- ROWNUM does not ensure that records are fetched in any particular record. If you fire a query like
SELECT * FROM emp WHERE rownum < 10
Oracle does not guarantee you will get same set of 10 row very time. The ORDER BY clause will help to overcome this unpredictable behavior.
 
First, you drop a couch from the plane, THEN you surf it. Here, take this tiny ad with you:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic