Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Select records N to N + 10 with order by clause
Message
General information
Forum:
Oracle
Category:
PL/SQL
Miscellaneous
Thread ID:
00703675
Message ID:
00704556
Views:
17
50,000 records is not a lot, I'm writing queries against tables with hundreds of millions of records. There are a number of things you can do to tune your queries, look at a book like SQL High Performance Tuning.

I can mention some things that may help.
In most cases you should aviod full table scans where possible. In your query you are forcing multiple full table scans.
Select only the cloumns you need.
With internet apps you usually want to set your otimizer to optimize for returning the first row rather than the entire table.

In this case I would create a cursor like this
CURSOR cCases IS
SELECT id_accident_case_data FROM accident_case_data ORDER BY accident_case_data.inj_name desc;
Loop through the first 10 rows of the table, store data to a PL/SQL table (or array) indexed by the row number then display the info from the array.

Retrieve just the rows that you need. If the user pages backwards then retrieve the data from previous pages in the array.

If you are using ADO or similar a type of record set then make it server side.

-- George

>Hi,
>
>We have a web application backending onto an Oracle 9i database.
>
>We have a requirement to do a query against the tables and display browse screens from which the user can select the record he wishes to view/edit. The screen displays ten records at a time, with 4 or 5 fields from the table displayed in a grid. The user can order by any of those 4 or 5 fields. In addition, the user can select from hyperlinks at the bottom of the screen to see the first 10 records, records 11 to 20 etc.
>
>The following query works, but doesn't order the data:
>
>(SELECT id_accident_case_data FROM (SELECT accident_case_data.id_accident_case_data,accident_case_data.form2no,accident_case_data.inj_name,accident_case_data.hkid,accident_case_data.emp_name FROM accident_case_data ORDER BY accident_case_data.inj_name desc) where rownum <= 10) MINUS (SELECT id_accident_case_data FROM (SELECT accident_case_data.id_accident_case_data,accident_case_data.form2no,accident_case_data.inj_name,accident_case_data.hkid,accident_case_data.emp_name FROM accident_case_data ORDER BY accident_case_data.inj_name desc) where rownum < 1);
>
>Any attempt we have used to order the result, for instance by doing the following:
>
>(SELECT id_accident_case_data FROM (SELECT accident_case_data.id_accident_case_data,accident_case_data.form2no,accident_case_data.inj_name,accident_case_data.hkid,accident_case_data.emp_name FROM accident_case_data ORDER BY accident_case_data.inj_name desc) where rownum <= 10 ORDER BY inj_name desc) MINUS (SELECT id_accident_case_data FROM (SELECT accident_case_data.id_accident_case_data,accident_case_data.form2no,accident_case_data.inj_name,accident_case_data.hkid,accident_case_data.emp_name FROM accident_case_data ORDER BY accident_case_data.inj_name desc) where rownum < 1 ORDER BY inj_name desc);
>
>results in the error "Missing right parenthesis".
>
>Anyone got any idea how to proceed ?
>
>Best.
>
>Matt.
George
Previous
Reply
Map
View

Click here to load this message in the networking platform