473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Returning record X-Y from a table

Hi there,

Looking for a way of returning the Xth to Yth records of an Oracle database
I thought using ROWNUM. Here is the solution I came up with.

SELECT * FROM
(
SELECT
ROWNUM RECID,
t.*,
FROM
table t
WHERE
(ROWNUM BETWEEN 1 AND Y) AND
(whatever condition you want on your table)
)
WHERE
RECID >= X

It work great for me so far, but my tables aren't very big (a few thousands
records).

Is anybody aware of any kind of issues using this query as the table get
bigger and, if yes, is there any way to optimize this. (They are history
tables and will definitely get huge at some point).

I assumed that as this query is processed entirely on the Oracle server the
performance sould be better than if I had queried the top Y records and
filtered out the top X records on the client side.

Thanks for your advice.

JB Fidelia.

Jul 19 '05 #1
2 4049

"news" <jb*******@multicorpora.ca> wrote in message
news:Vq******************@wagner.videotron.net...
Hi there,

Looking for a way of returning the Xth to Yth records of an Oracle database I thought using ROWNUM. Here is the solution I came up with.

SELECT * FROM
(
SELECT
ROWNUM RECID,
t.*,
FROM
table t
WHERE
(ROWNUM BETWEEN 1 AND Y) AND
(whatever condition you want on your table)
)
WHERE
RECID >= X

It work great for me so far, but my tables aren't very big (a few thousands records).

Is anybody aware of any kind of issues using this query as the table get
bigger and, if yes, is there any way to optimize this. (They are history
tables and will definitely get huge at some point).

I assumed that as this query is processed entirely on the Oracle server the performance sould be better than if I had queried the top Y records and
filtered out the top X records on the client side.
How do you in wich order the will be output since there is no ORDER BY in
your query??

But anyway the point is that if you want to avoid scanning the whole table
(to produce the rownum that you use) you should add column to your table,
say RECID, and assign a unique number to RECID with a sequence. Then if you
create a index on this column RECID, you will get your performance...
SELECT *
FROM table t WHERE
(ROWNUM BETWEEN 1 AND Y) AND
(whatever condition you want on your table) Thanks for your advice.

JB Fidelia.

Jul 19 '05 #2
"news" <jb*******@multicorpora.ca> wrote in message
news:Vq******************@wagner.videotron.net...
Hi there,

Looking for a way of returning the Xth to Yth records of an Oracle database I thought using ROWNUM. Here is the solution I came up with.

SELECT * FROM
(
SELECT
ROWNUM RECID,
t.*,
FROM
table t
WHERE
(ROWNUM BETWEEN 1 AND Y) AND
(whatever condition you want on your table)
)
WHERE
RECID >= X

It work great for me so far, but my tables aren't very big (a few thousands records).

Is anybody aware of any kind of issues using this query as the table get
bigger and, if yes, is there any way to optimize this. (They are history
tables and will definitely get huge at some point).

I assumed that as this query is processed entirely on the Oracle server the performance sould be better than if I had queried the top Y records and
filtered out the top X records on the client side.

Thanks for your advice.

JB Fidelia.


Your above query is not very efficient, ROWNUM is a pseudo column so it
means querying the entire database (at least up to "Y" records) every time
to retrieve a subset. For example, supposing you had 100,000 records in
your table and you wanted to retrieve just the last 5, your query would
require scanning 99,995 records just to get to the first retreivable record.
As the previous poster mentioned, it's better to create a unique, indexed
field and assign it a value from a sequence, and do your queries based on
this field instead of ROWNUM.
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Sugapablo | last post by:
Let's say I create a new record in a table like this: mysql_query("INSERT INTO table (col1) VALUES ('example')",$conn); ....that had an auto-incrementing, unique identifying column named "ID"...
4
by: Michael Trosen | last post by:
Hi Everyone, I hope someone can help, I'm pretty new to pro*c programming. I have the following application setup: a pro*c program calls a stored procedure and recieves a cursor back: the...
25
by: Andreas Fromm | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, Im building an user database with many tables keeping the data for the Address, Phone numbers, etc which are referenced by a table where I...
1
by: Ben | last post by:
I have a Tabular form bound to a table. The purpose of this form is to get times from a timer and record them in a field. The timer dumps the time automatically through a serial port. When the time...
11
by: klove1209 | last post by:
Good afternoon, Can someone please guide me towards how to return records from a table. I currently have a table with about 21 fields, and 21 records. I have one field that is just text and the...
5
by: littlevikinggirl | last post by:
Hi, I posted a badly worded question last week so got no replies and am still struggling to figure out the problem myself. I have a table containing two fields, Location and Serial Number. I...
1
by: vinodkus | last post by:
I M BEGINNER IN ASP I WANT TO RETURN TOTAL RECORDS FROM A TABLE. THERE ARE TWO FORMS CLASS1.ASP AND CLASS2.ASP THROUGH FIRST FORM I JUST POST THE NAME OF TABLE SO I M WRITING THE CODE OF...
5
by: jennwilson | last post by:
Using Access 2000 - I have a query that is suppose to return the records from table within specified time range and find matching data from another table . Table houses Clinician name, location...
1
by: news | last post by:
Hi there, Looking for a way of returning the Xth to Yth records of an Oracle database I thought using ROWNUM. Here is the solution I came up with. SELECT * FROM ( SELECT ROWNUM RECID, t.*,
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.