Query pagination
Hi, does anybody have a good way to paging a 'select' query, please send me and example query, thanks for you help!!!!!!!!!!
Hi.
There are a number of threads about this on asktom.oracle.com. Just search on the word "pagination". Here's an example:
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:76812348057
Cheers
Tim...
Similar Messages
-
Pagination query help needed for large table - force a different index
I'm using a slight modification of the pagination query from over at Ask Tom's: [http://www.oracle.com/technology/oramag/oracle/07-jan/o17asktom.html]
Mine looks like this when fetching the first 100 rows of all members with last name Smith, ordered by join date:
SELECT members.*
FROM members,
SELECT RID, rownum rnum
FROM
SELECT rowid as RID
FROM members
WHERE last_name = 'Smith'
ORDER BY joindate
WHERE rownum <= 100
WHERE rnum >= 1
and RID = members.rowidThe difference between this and the one at Ask Tom's is that my innermost query just returns the ROWID. Then in the outermost query we join the ROWIDs returned to the members table, after we have pruned the ROWIDs down to only the chunk of 100 we want. This makes it MUCH faster (verifiably) on our large tables, as it is able to use the index on the innermost query (well... read on).
The problem I have is this:
SELECT rowid as RID
FROM members
WHERE last_name = 'Smith'
ORDER BY joindateThis will use the index for the predicate column (last_name) instead of the unique index I have defined for the joindate column (joindate, sequence). (Verifiable with explain plan). It is much slower this way on a large table. So I can hint it using either of the following methods:
SELECT /*+ index(members, joindate_idx) */ rowid as RID
FROM members
WHERE last_name = 'Smith'
ORDER BY joindate
SELECT /*+ first_rows(100) */ rowid as RID
FROM members
WHERE last_name = 'Smith'
ORDER BY joindateEither way, it now uses the index of the ORDER BY column (joindate_idx), so now it is much faster as it does not have to do a sort (remember, VERY large table, millions of records). So that seems good. But now, on my outermost query, I join the rowid with the meaningful columns of data from the members table, as commented below:
SELECT members.* -- Select all data from members table
FROM members, -- members table added to FROM clause
SELECT RID, rownum rnum
FROM
SELECT /*+ index(members, joindate_idx) */ rowid as RID -- Hint is ignored now that I am joining in the outer query
FROM members
WHERE last_name = 'Smith'
ORDER BY joindate
WHERE rownum <= 100
WHERE rnum >= 1
and RID = members.rowid -- Merge the members table on the rowid we pulled from the inner queriesOnce I do this join, it goes back to using the predicate index (last_name) and has to perform the sort once it finds all matching values (which can be a lot in this table, there is high cardinality on some columns).
So my question is, in the full query above, is there any way I can get it to use the ORDER BY column for indexing to prevent it from having to do a sort? The join is what causes it to revert back to using the predicate index, even with hints. Remove the join and just return the ROWIDs for those 100 records and it flies, even on 10 million records.
It'd be great if there was some generic hint that could accomplish this, such that if we change the table/columns/indexes, we don't need to change the hint (the FIRST_ROWS hint is a good example of this, while the INDEX hint is the opposite), but any help would be appreciated. I can provide explain plans for any of the above if needed.
Thanks!Lakmal Rajapakse wrote:
OK here is an example to illustrate the advantage:
SQL> set autot traceonly
SQL> select * from (
2 select a.*, rownum x from
3 (
4 select a.* from aoswf.events a
5 order by EVENT_DATETIME
6 ) a
7 where rownum <= 1200
8 )
9 where x >= 1100
10 /
101 rows selected.
Execution Plan
Plan hash value: 3711662397
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1200 | 521K| 192 (0)| 00:00:03 |
|* 1 | VIEW | | 1200 | 521K| 192 (0)| 00:00:03 |
|* 2 | COUNT STOPKEY | | | | | |
| 3 | VIEW | | 1200 | 506K| 192 (0)| 00:00:03 |
| 4 | TABLE ACCESS BY INDEX ROWID| EVENTS | 253M| 34G| 192 (0)| 00:00:03 |
| 5 | INDEX FULL SCAN | EVEN_IDX02 | 1200 | | 2 (0)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter("X">=1100)
2 - filter(ROWNUM<=1200)
Statistics
0 recursive calls
0 db block gets
443 consistent gets
0 physical reads
0 redo size
25203 bytes sent via SQL*Net to client
281 bytes received via SQL*Net from client
8 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
101 rows processed
SQL>
SQL>
SQL> select * from aoswf.events a, (
2 select rid, rownum x from
3 (
4 select rowid rid from aoswf.events a
5 order by EVENT_DATETIME
6 ) a
7 where rownum <= 1200
8 ) b
9 where x >= 1100
10 and a.rowid = rid
11 /
101 rows selected.
Execution Plan
Plan hash value: 2308864810
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1200 | 201K| 261K (1)| 00:52:21 |
| 1 | NESTED LOOPS | | 1200 | 201K| 261K (1)| 00:52:21 |
|* 2 | VIEW | | 1200 | 30000 | 260K (1)| 00:52:06 |
|* 3 | COUNT STOPKEY | | | | | |
| 4 | VIEW | | 253M| 2895M| 260K (1)| 00:52:06 |
| 5 | INDEX FULL SCAN | EVEN_IDX02 | 253M| 4826M| 260K (1)| 00:52:06 |
| 6 | TABLE ACCESS BY USER ROWID| EVENTS | 1 | 147 | 1 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - filter("X">=1100)
3 - filter(ROWNUM<=1200)
Statistics
8 recursive calls
0 db block gets
117 consistent gets
0 physical reads
0 redo size
27539 bytes sent via SQL*Net to client
281 bytes received via SQL*Net from client
8 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
101 rows processed
Lakmal (and OP),
Not sure what advantage you are trying to show here. But considering that we are talking about pagination query here and order of records is important, your 2 queries will not always generate output in same order. Here is the test case:
SQL> select * from v$version ;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
SQL> show parameter optimizer
NAME TYPE VALUE
optimizer_dynamic_sampling integer 2
optimizer_features_enable string 10.2.0.1
optimizer_index_caching integer 0
optimizer_index_cost_adj integer 100
optimizer_mode string ALL_ROWS
optimizer_secure_view_merging boolean TRUE
SQL> show parameter pga
NAME TYPE VALUE
pga_aggregate_target big integer 103M
SQL> create table t nologging as select * from all_objects where 1 = 2 ;
Table created.
SQL> create index t_idx on t(last_ddl_time) nologging ;
Index created.
SQL> insert /*+ APPEND */ into t (owner, object_name, object_id, created, last_ddl_time) select owner, object_name, object_id, created, sysdate - dbms_random.value(1, 100) from all_objects order by dbms_random.random;
40617 rows created.
SQL> commit ;
Commit complete.
SQL> exec dbms_stats.gather_table_stats(user, 'T', cascade=>true);
PL/SQL procedure successfully completed.
SQL> select object_id, object_name, created from t, (select rid, rownum rn from (select rowid rid from t order by created desc) where rownum <= 1200) t1 where rn >= 1190 and t.rowid = t1.rid ;
OBJECT_ID OBJECT_NAME CREATED
47686 ALL$OLAP2_JOIN_KEY_COLUMN_USES 28-JUL-2009 08:08:39
47672 ALL$OLAP2_CUBE_DIM_USES 28-JUL-2009 08:08:39
47681 ALL$OLAP2_CUBE_MEASURE_MAPS 28-JUL-2009 08:08:39
47682 ALL$OLAP2_FACT_LEVEL_USES 28-JUL-2009 08:08:39
47685 ALL$OLAP2_AGGREGATION_USES 28-JUL-2009 08:08:39
47692 ALL$OLAP2_CATALOGS 28-JUL-2009 08:08:39
47665 ALL$OLAPMR_FACTTBLKEYMAPS 28-JUL-2009 08:08:39
47688 ALL$OLAP2_DIM_LEVEL_ATTR_MAPS 28-JUL-2009 08:08:39
47689 ALL$OLAP2_DIM_LEVELS_KEYMAPS 28-JUL-2009 08:08:39
47669 ALL$OLAP9I2_HIER_DIMENSIONS 28-JUL-2009 08:08:39
47666 ALL$OLAP9I1_HIER_DIMENSIONS 28-JUL-2009 08:08:39
11 rows selected.
SQL> select object_id, object_name, last_ddl_time from t, (select rid, rownum rn from (select rowid rid from t order by last_ddl_time desc) where rownum <= 1200) t1 where rn >= 1190 and t.rowid = t1.rid ;
OBJECT_ID OBJECT_NAME LAST_DDL_TIME
11749 /b9fe5b99_OraRTStatementComman 06-FEB-2010 03:43:49
13133 oracle/jdbc/driver/OracleLog$3 06-FEB-2010 03:45:44
37534 com/sun/mail/smtp/SMTPMessage 06-FEB-2010 03:46:14
36145 /4e492b6f_SerProfileToClassErr 06-FEB-2010 03:11:09
26815 /7a628fb8_DefaultHSBChooserPan 06-FEB-2010 03:26:55
16695 /2940a364_RepIdDelegator_1_3 06-FEB-2010 03:38:17
36539 sun/io/ByteToCharMacHebrew 06-FEB-2010 03:28:57
14044 /d29b81e1_OldHeaders 06-FEB-2010 03:12:12
12920 /25f8f3a5_BasicSplitPaneUI 06-FEB-2010 03:11:06
42266 SI_GETCLRHSTGRFTR 06-FEB-2010 03:40:20
15752 /2f494dce_JDWPThreadReference 06-FEB-2010 03:09:31
11 rows selected.
SQL> select object_id, object_name, last_ddl_time from (select t1.*, rownum rn from (select * from t order by last_ddl_time desc) t1 where rownum <= 1200) where rn >= 1190 ;
OBJECT_ID OBJECT_NAME LAST_DDL_TIME
37534 com/sun/mail/smtp/SMTPMessage 06-FEB-2010 03:46:14
13133 oracle/jdbc/driver/OracleLog$3 06-FEB-2010 03:45:44
11749 /b9fe5b99_OraRTStatementComman 06-FEB-2010 03:43:49
42266 SI_GETCLRHSTGRFTR 06-FEB-2010 03:40:20
16695 /2940a364_RepIdDelegator_1_3 06-FEB-2010 03:38:17
36539 sun/io/ByteToCharMacHebrew 06-FEB-2010 03:28:57
26815 /7a628fb8_DefaultHSBChooserPan 06-FEB-2010 03:26:55
14044 /d29b81e1_OldHeaders 06-FEB-2010 03:12:12
36145 /4e492b6f_SerProfileToClassErr 06-FEB-2010 03:11:09
12920 /25f8f3a5_BasicSplitPaneUI 06-FEB-2010 03:11:06
15752 /2f494dce_JDWPThreadReference 06-FEB-2010 03:09:31
11 rows selected.
SQL> select object_id, object_name, last_ddl_time from t, (select rid, rownum rn from (select rowid rid from t order by last_ddl_time desc) where rownum <= 1200) t1 where rn >= 1190 and t.rowid = t1.rid order by last_ddl_time desc ;
OBJECT_ID OBJECT_NAME LAST_DDL_TIME
37534 com/sun/mail/smtp/SMTPMessage 06-FEB-2010 03:46:14
13133 oracle/jdbc/driver/OracleLog$3 06-FEB-2010 03:45:44
11749 /b9fe5b99_OraRTStatementComman 06-FEB-2010 03:43:49
42266 SI_GETCLRHSTGRFTR 06-FEB-2010 03:40:20
16695 /2940a364_RepIdDelegator_1_3 06-FEB-2010 03:38:17
36539 sun/io/ByteToCharMacHebrew 06-FEB-2010 03:28:57
26815 /7a628fb8_DefaultHSBChooserPan 06-FEB-2010 03:26:55
14044 /d29b81e1_OldHeaders 06-FEB-2010 03:12:12
36145 /4e492b6f_SerProfileToClassErr 06-FEB-2010 03:11:09
12920 /25f8f3a5_BasicSplitPaneUI 06-FEB-2010 03:11:06
15752 /2f494dce_JDWPThreadReference 06-FEB-2010 03:09:31
11 rows selected.
SQL> set autotrace traceonly
SQL> select object_id, object_name, last_ddl_time from t, (select rid, rownum rn from (select rowid rid from t order by last_ddl_time desc) where rownum <= 1200) t1 where rn >= 1190 and t.rowid = t1.rid order by last_ddl_time desc
2 ;
11 rows selected.
Execution Plan
Plan hash value: 44968669
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1200 | 91200 | 180 (2)| 00:00:03 |
| 1 | SORT ORDER BY | | 1200 | 91200 | 180 (2)| 00:00:03 |
|* 2 | HASH JOIN | | 1200 | 91200 | 179 (2)| 00:00:03 |
|* 3 | VIEW | | 1200 | 30000 | 98 (0)| 00:00:02 |
|* 4 | COUNT STOPKEY | | | | | |
| 5 | VIEW | | 40617 | 475K| 98 (0)| 00:00:02 |
| 6 | INDEX FULL SCAN DESCENDING| T_IDX | 40617 | 793K| 98 (0)| 00:00:02 |
| 7 | TABLE ACCESS FULL | T | 40617 | 2022K| 80 (2)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("T".ROWID="T1"."RID")
3 - filter("RN">=1190)
4 - filter(ROWNUM<=1200)
Statistics
1 recursive calls
0 db block gets
348 consistent gets
0 physical reads
0 redo size
1063 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
11 rows processed
SQL> select object_id, object_name, last_ddl_time from (select t1.*, rownum rn from (select * from t order by last_ddl_time desc) t1 where rownum <= 1200) where rn >= 1190 ;
11 rows selected.
Execution Plan
Plan hash value: 882605040
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1200 | 62400 | 80 (2)| 00:00:01 |
|* 1 | VIEW | | 1200 | 62400 | 80 (2)| 00:00:01 |
|* 2 | COUNT STOPKEY | | | | | |
| 3 | VIEW | | 40617 | 1546K| 80 (2)| 00:00:01 |
|* 4 | SORT ORDER BY STOPKEY| | 40617 | 2062K| 80 (2)| 00:00:01 |
| 5 | TABLE ACCESS FULL | T | 40617 | 2062K| 80 (2)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter("RN">=1190)
2 - filter(ROWNUM<=1200)
4 - filter(ROWNUM<=1200)
Statistics
0 recursive calls
0 db block gets
343 consistent gets
0 physical reads
0 redo size
1063 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
11 rows processed
SQL> select object_id, object_name, last_ddl_time from t, (select rid, rownum rn from (select rowid rid from t order by last_ddl_time desc) where rownum <= 1200) t1 where rn >= 1190 and t.rowid = t1.rid ;
11 rows selected.
Execution Plan
Plan hash value: 168880862
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1200 | 91200 | 179 (2)| 00:00:03 |
|* 1 | HASH JOIN | | 1200 | 91200 | 179 (2)| 00:00:03 |
|* 2 | VIEW | | 1200 | 30000 | 98 (0)| 00:00:02 |
|* 3 | COUNT STOPKEY | | | | | |
| 4 | VIEW | | 40617 | 475K| 98 (0)| 00:00:02 |
| 5 | INDEX FULL SCAN DESCENDING| T_IDX | 40617 | 793K| 98 (0)| 00:00:02 |
| 6 | TABLE ACCESS FULL | T | 40617 | 2022K| 80 (2)| 00:00:01 |
Predicate Information (identified by operation id):
1 - access("T".ROWID="T1"."RID")
2 - filter("RN">=1190)
3 - filter(ROWNUM<=1200)
Statistics
0 recursive calls
0 db block gets
349 consistent gets
0 physical reads
0 redo size
1063 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
11 rows processed
SQL> select object_id, object_name, last_ddl_time from (select t1.*, rownum rn from (select * from t order by last_ddl_time desc) t1 where rownum <= 1200) where rn >= 1190 order by last_ddl_time desc ;
11 rows selected.
Execution Plan
Plan hash value: 882605040
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1200 | 62400 | 80 (2)| 00:00:01 |
|* 1 | VIEW | | 1200 | 62400 | 80 (2)| 00:00:01 |
|* 2 | COUNT STOPKEY | | | | | |
| 3 | VIEW | | 40617 | 1546K| 80 (2)| 00:00:01 |
|* 4 | SORT ORDER BY STOPKEY| | 40617 | 2062K| 80 (2)| 00:00:01 |
| 5 | TABLE ACCESS FULL | T | 40617 | 2062K| 80 (2)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter("RN">=1190)
2 - filter(ROWNUM<=1200)
4 - filter(ROWNUM<=1200)
Statistics
175 recursive calls
0 db block gets
388 consistent gets
0 physical reads
0 redo size
1063 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
4 sorts (memory)
0 sorts (disk)
11 rows processed
SQL> set autotrace off
SQL> spool offAs you will see, the join query here has to have an ORDER BY clause at the end to ensure that records are correctly sorted. You can not rely on optimizer choosing NESTED LOOP join method and, as above example shows, when optimizer chooses HASH JOIN, oracle is free to return rows in no particular order.
The query that does not involve join always returns rows in the desired order. Adding an ORDER BY does add a step in the plan for the query using join but does not affect the other query. -
Issue While executing the Query for Pagination using ROWNUM with like
Issue While executing the Query for Pagination using ROWNUM with like.
Database is Oracle11G.
Oracle Database Table contains 8-9 lakh records
1) SQL equal (=)
SELECT /*+ FIRST_ROWS(n) */ ROWNUM RNUM, A.* FROM LINE A
WHERE A.REFERENCE = 'KMF22600920'
Execution Time:- 0.00869245 seconds
Returns 2 resultsets
2) SQL like (one %)
SELECT /*+ FIRST_ROWS(n) */ ROWNUM RNUM, A.* FROM LINE A
WHERE A.REFERENCE = 'KMF22600920%'
Execution Time:- 0.01094301 seconds
Returns 2 resultsets
3) SQL like (two%)
SELECT /*+ FIRST_ROWS(n) */ ROWNUM RNUM, A.* FROM LINE A
WHERE A.REFERENCE like '%KMF22600920%'
Execution Time:- 6.43989658 seconds
Returns 2 resultsets
In Pagination, we are using Modified version of SQL Query 3) with ROWNUM as mentioned below :-
4) SELECT * FROM (
SELECT /*+ FIRST_ROWS(n) */ ROWNUM RNUM, A.* FROM LINE A
WHERE REFERENCE like '%KMF22600920%' AND ROWNUM <= 20 ) WHERE RNUM > 0
Execution Time:- Infinite
ResultSets:- No as execution time is infinite
a) Instead of like if we use = in the above query it is returning the 2 resultsets (execution time 0.02699282 seconds)
b) Instead of two % in the above query, if use one example REFERENCE like 'KMF22600920%' it is returning the 2 resultsets (execution time 0.03313019 seconds)
Issue:- When using two % in like in the above query i.e. REFERENCE like '%KMF22600920%' AND ROWNUM <= 20 ) , it is going to infinite.
Could you please let us know what is the issue with two % used in like and rownum
5) Modified version of Option1 query (move out the RNUM condition AND RNUM <= 20)
SELECT * FROM (
SELECT /*+ FIRST_ROWS(n) */ ROWNUM RNUM, A.* FROM LINE A
WHERE REFERENCE like '%KMF22600920%' ) WHERE RNUM > 0 AND RNUM <= 20
Execution Time:- 7.41368914 seconds
Returns 2 resultsets
Is the above query is best optimized query which should be used for the Pagination or still can improve on this ?This would be easier to diagnose if there was an explain plan posted for the 'good' and 'bad' queries. Generally speaking using '%' on both sides precludes the use of any indexes.
-
Help In Paginating Query output
Hi All,
I have a query which fetches 80000 records at one short. This fetching can be controlled by using the search criteria. But some times it needs to fetch all the records and populate on the screen. The query fetches and populates more than 50 columns and which takes more time.
What i want is to fetch all the records but display only 10 of them at a time and provide pagination option like 1,2,3.... So when the user clicks on page 3, he will get the records 21-20 and page 4 records 31-40 and so on. If he want to again view page 1 then he should get records 1-10.
How can i write a stored procedure to achive this and how to store the counters of this search?
What is the best way to do this (alternate processes using PL/SQL)?
Any explanations and solution to this will be of great help.
Regards
SwadhinSwadhin,
One quick way I can think of is to have a sort order column in your
table. The PL/SQL stored procedure would just take the upper and lower
limits as parameters and query data. You just need to call
the same procedure, passing it the appropriate upper and lower limits (which
you would match against the sort order column). The limits would change
for each link on a page.
This approach would avoid dumping all the 80k records at one shot which is
unnecessary. You can also avoid caching data on a client buffer.
Just one way of doing it. There could be more efficient ways to achieve this.
Rgds.
Amogh -
Sql Query(Updateable Report) with pagination
Hi,
We're on APEX 3.2 I have a question on Sql Query(Updateable Report) and pagination. I have an updateable report which we have set to show 20 rows. When the userwhi has more than 20 rows enters the data and clicks next the data disappears. I have been reviewing other posts, but haven't come to a clear conclusion on how to prevent this from happening. I have been trying to use javascript to show a save popup when clicking 'Next' Any help is appreciated.
Thanks,
Joeany ideas?
-
Query Result with pagination problem
I have a region that has a search field with a "Go" button which runs a report based on a SQL Query(PL/SQL function body returning SQL query). Works great and displays the default of 15 rows with a pagination scheme of "Row Ranges X to Y of Z(with pagination)". The problem is that when I click on the "Next rows ... " link the screen goes blank and I have to click on the "Go" button before it displays the next 15 rows. How do I get around this problem of having to click on the "Go" button?
thanks
JohnHi John,
I am also facing the same problem. Any solution has been found out by you.
If so, please give it in the forum know.
Thanks in advance
kavitha l -
How to apply pagination to data bind to asp:Repeater control using Camel Query.
Hi All,
I am having a <asp:Repeater> control to which i bind the data from share point list.
I want to apply pagination to that data which is bind to Repeater. I am using CAMEL query to get data from list.
How can i apply the pagination to this data fetch by camel which is bined to Repeater control.
Thanks
amolHi,
From your description, you might want to use CAML to query the needed items from a SharePoint list, then use a Repeater control to bind to these data with paging allowed.
If so, here is a solution like this: Use
CAML to query a collection of items and save them into a
DataTable object. Then use the PagedDataSource object to achieve the paging for us and associate it to a
Repeater control.
Here are two links will provide more details:
http://social.msdn.microsoft.com/Forums/sharepoint/en-US/7af4c865-a44a-4ccb-864d-9d834f8b2b87/bind-sharepoint-list-to-asp-repeater?forum=sharepointdevelopment
http://sharepointdotnetfalls.blogspot.in/2013/07/repeater-control-with-paging-in-share.html
Best regards
Patrick Liang
TechNet Community Support -
Help, how to Query database using pagination
hi,
how to Query database using pagination for the large data,
any API to do this?
thank you in advance!Hi,
You can specify XmlQueryContext::Lazy as your evaluation type, and only call XmlResults::next() as many times as you need results from it.
John -
Achieve dynamic pagination with sql query
Hi All,
I want to achieve pagination as you are seeing in this forum.
example:
My query condition satisfies for 100 records. But since i have implement pagination. Assume I am displaying 10 records at a time.
So, First time 10 records will be displayed. And 1,2,3,4...10 will be displayed at top.
When I click at page 2 then my query should fetch 20-30 records. for page 3 it should fetch 30-40. ........
The whole purpose is to achieve pagination without hit on database and without in memory object.
Thanks
PunitHi, Punit,
This looks like a revised version of another thread you started:
Problem in fetching rows randomly
Please don't post the same question twice. Mark one of your threads as "Answered" right away, and only continue with the other one.
The solution I posted in your other thread involves running a new query every time you want another page of information. That's very much like the way the "Thread List" on this forum works: it shows, say rows 1 through 15 in order by modification date (descending). If you ask for the next page, it does another query to get rows 16 though 30. If new threads are added between the two queries, then the same item that was #15 in the first query may appear as #16 (or higher) on the second query.
If you want a consistent result set that only executes the base query once, then you have to store the results of the base query, and then show pages from those stored results. Using pure SQL, you could store the results in another table; a Global Temporary Table would probably be best. -
Sql query w/search field, pagination issue
I have a page with a query which uses a search field. I am able to scroll through to different pages of the results.
How can I always make certain that the results returned start on pagination = 1. For example:
I leave P10_SEARCH_FIELD = null and scroll to page 2 (item 11-20). I then do a search for 'VAN'. The results return, however rather than page 1 appearing, page 2 appears. Is there a way to reset pagination so that it will always show the first item?
thanksnever mind. in the branch I checked the reset pagination for this page and that did the trick.
-
Pagination in toplink using custom query
Re: Pagination using TopLink
Posted: Aug 31, 2006 10:42 PM in response to: Shaun Smith Reply
Hi,
I have my own customer query which is really complex with subqueries,joins,grouping,aggregation in the query etc etc for which I cant use toplink workbench to create a project and do the metadata mapping.
But we need to enable pagination without holding the database resources between customer's page time in the browser.
Is there any provision in toplink to just input the custom query (either statement/prepared statement) and do pagination without holding connection to the database between page time?
The example i got from the link makes use of LogicalCursor/ChunkingLogicalCursor etc.
LogicalCursor cursor = new LogicalCursor(Model.class,null);
for (CursorIterator it = cursor.iterator(session); it.hasNext();)
System.out.println(it.next(session));
Only parameter that is passed to the LogicalCursor is "Model" which is a java object mapped to a particular table.
But we had a java object which should be mapped to the output of a complex query involing complex query and pagination needs to be enabled.
Could you please let us know a sample by which we can do by simply passing the query during the runtime ?It really seems weird.
We followed the toplink tutorial and wrote a servlet FindAddress which on receiving the request
1. instantiates ReadQuery and
2. setreferenceclass to Address.class,
3. setFetchSize(1000) and
4.sets useScrollableCursor.
5. It does session.executeQuery returning a ScrollableCursor.
6. We place the ScrollableCursor in HttpSession
and then redirect the page to viewAddress.jsp which
1. retrieves the ScrollableCursor from the session
2. i=0; while(cursor.hasNext() && i<1000) {
Address address = (Address)cursor.next();
//display via the jsp all these 1000 address objects
3. has a next button when a click on that it again goes to the same page retrieving the next set of 1000 records from ScrollableCursor from the session.
Through out this experimentation I could see the connection is still held. I was expecting that once the page gets displayed for 1000 records and untill you press next, the connection should be handled back to the J2EE application server but still the connection is held .
The logic of setFetchSize as mentioned in the documentation is that after reading the first set of records as per fetchSize ,connection should be returned to the pool and when we do iterator.next() after fetchsize limit, it has to again going to the database and fetch records but it doesnt seem to be.
Could you please help us. This is what we are trying to do as next step and we had been evaluating toplink could be the best choice for our business scneario:
We try to achieve pagination without holding the database resource when the user navigates between paged records.
Any help on this would make us to hit toplink for our huge application.
Here is the attached FindAddress.java and ViewAddress.jsp
FindAddress.java
=============
// Decompiled by DJ v2.9.9.61 Copyright 2000 Atanas Neshkov Date: 9/8/2006 6:32:21 PM
// Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
// Decompiler options: packimports(3)
// Source File Name: FindAddress.java
package examples.servletjsp;
import java.io.IOException;
import java.io.PrintStream;
import javax.servlet.*;
import javax.servlet.http.*;
import oracle.toplink.expressions.Expression;
import oracle.toplink.expressions.ExpressionBuilder;
import oracle.toplink.queryframework.ReadAllQuery;
import oracle.toplink.queryframework.ScrollableCursor;
import oracle.toplink.threetier.ClientSession;
import oracle.toplink.threetier.Server;
// Referenced classes of package examples.servletjsp:
// JSPDemoServlet
public class FindAddress extends JSPDemoServlet
public FindAddress()
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
doPost(request, response);
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
request.setCharacterEncoding("UTF-8");
getServletContext().log("FindAddress servlet - doPost");
java.util.Vector address = null;
ScrollableCursor cursor = null;
try
HttpSession session = request.getSession(true);
ReadAllQuery query = new ReadAllQuery();
query.setReferenceClass(examples.servletjsp.model.Address.class);
ExpressionBuilder builder = new ExpressionBuilder();
query.setSelectionCriteria(builder.get("id").greaterThan(100));
query.setFetchSize(5000);
query.useScrollableCursor();
System.out.println("########### Sleep Mode Before assigning to CURSOR ###############");
System.out.println("############ Back from Sleep Mode before CURSOR ############");
cursor = (ScrollableCursor)((Server)getSession()).acquireClientSession().executeQuery(query);
System.out.println("############ Sleep Mode After assigning to CURSOR ###########");
System.out.println("############ Back from Sleep Mode After CURSOR ############");
session.setAttribute("ScrollableCursor", cursor);
catch(Exception e)
request.setAttribute("source", "FindEmployees doPost");
request.setAttribute("header", "An Error Occurred");
request.setAttribute("errorMessage", e.getMessage());
request.getRequestDispatcher("./errorPage.jsp").forward(request, response);
return;
System.out.println("cursor------------" + (cursor == null));
if(cursor == null)
request.getRequestDispatcher("./EmployeesNotFound.jsp").forward(request, response);
} else
request.setAttribute("address", address);
request.getRequestDispatcher("./viewAddress.jsp").forward(request, response);
viewAddress.jsp
=============
<%@page import="java.util.*"%>
<%@page import="examples.servletjsp.*"%>
<%@page import="examples.servletjsp.model.*"%>
<%@page import="oracle.toplink.queryframework.ScrollableCursor"%>
<%@page import="java.math.*"%>
<%@page contentType = "text/html; charset=UTF-8"%>
<html>
<head><title>Employee Query Results</title></head>
<body>
<form name="test" method="post" action="viewAddress.jsp">
<!-- Prepare s heading.
Get the employees passed in from ViewEmployees servlet. Show them in table format. Provide button
to ViewEmployee -->
<%
request.setCharacterEncoding("UTF-8");
String searchString = request.getParameter("employeeString");
ScrollableCursor cursor = (ScrollableCursor) session.getAttribute("ScrollableCursor");
String heading = null;
heading="Search Results for FindAll on Employee";
String employeeData = "";
//Iterator data = ((Vector)request.getAttribute("address")).iterator();
int i =0;
while(cursor.hasNext() && i<4995) {
if(i<10){
System.out.println("######### JSP Count TRhread Sleep ###########");
//Thread.sleep(100);
//System.out.println("######### JSP Count TRhread Sleep Over ###########");
i++;
Address address = (Address)cursor.next();
BigDecimal id = address.getId();
String city = address.getCity();
String province = address.getProvince();
String street = address.getStreet();
String country = address.getCountry();
String pCode = address.getPostalCode();
employeeData += "<tr><td>" + id + "</td>"
+ "<td>" + province + "</td>"
+ "<td>" + street + "</td>"
+ "<td>" + city + "</td>"
+ "<td>" + pCode + "</td>"
+ "<td>" + country+ "</td>"
+ "</tr>";
//cursor.close();
System.out.println("abcdAfter closing the cursor ->plz see whether connpool monitorcnt = 0");
%>
<center>
<h2><%=heading%></h2>
<hr>
Return to Main
<p>
<table border=1>
<tr>
<td align="center">Address Id</td>
<td align="center">Province</td>
<td align="center">Street</td>
<td align="center">City</td>
<td align="center">Postal Code</td>
<td align="center">Country</td></tr>
<%=employeeData %>
</table>
</center>
<p>
<input type="submit" name ="next" value="next" >
<center>Return to Main</center>
</form>
</body>
</html> -
Pagination resubmits the query to the database.
I have a standard report fed by a dynamic query to retrive the data based on the parameter passed. All parameters reside on one page and the report it self is on a new page. When user clicks a go button the report is submitted with a dynamic query based on the user input parameters. The report some times takes a minute or two to capture the result set and display and depending on the number of rows fetched spans multiple Paginations. We recently noticed that every time the next x row arrow is clicked the page is resubmitted and the query to the database is resubmitted and this is a bad experience to the user to wait another minute for the page to return next x rows. Please help resolve this issue.
Hi User XY,
this is the standard APEX behaviour, every time you want a new subset (get next/previous page) the query is executed again.
You can:
- read all rows at once
- tune your datamodel and/or query to get faster response
- prepare the data in an APEX Collection (e.g. with APEX_COLLECTION.CREATE_COLLECTION_FROM_QUERY*) and let your report read from the collection
brgds,
Peter
Blog: http://www.oracle-and-apex.com
ApexLib: http://apexlib.oracleapex.info
BuilderPlugin: http://builderplugin.oracleapex.info
Work: http://www.click-click.at -
I have a SELECT statement whcih is querying a very large table, i want to introduce pagination. Like I can send parameters the upper and lower limits in request for number of rows. Example: I want to query for first 100 results, then I want to query for 101 to 200 ..
I have already tested ROWNUM it fails as the data is in TBs (Tera Bytes)
The Query is:-
SELECT ROWNUM AS rownumber,
CASE
WHEN call_type IN ('002')
THEN subno
ELSE b_subno
END called_number,
CASE
WHEN call_type NOT IN ('002')
THEN subno
ELSE b_subno
END calling_number, act_duration DURATION, to_char(billamount,'99990.000') charges,
TO_CHAR (transdate, 'DD-MON-YY HH24:MI:SS') date_as_str,
CASE call_type
WHEN '001'
THEN 'Mobile orginating call'
WHEN '002'
THEN 'Mobile terminationg call'
WHEN '001'
THEN 'Mobile orginating call'
WHEN '003'
THEN 'Emergency call'
WHEN '004'
THEN 'PBX outgoing call'
WHEN '005'
THEN 'PBX incoming call '
WHEN '010'
THEN 'SS registration'
WHEN '011'
THEN 'SS erasure'
WHEN '012'
THEN 'SS activation'
WHEN '013'
THEN 'SS deactivation'
WHEN '014'
THEN 'SS interrogation'
WHEN '015'
THEN 'Unstructured SS data processing '
WHEN '026'
THEN 'Interrogation record'
WHEN '027'
THEN 'Transit record'
WHEN '029'
THEN 'Call forwarding'
WHEN '030'
THEN 'Mobile terminating SMS'
WHEN '031'
THEN 'Mobile originating SMS'
WHEN '032'
THEN 'Emergency call trace (ECT)'
WHEN '050'
THEN 'GPRS roaming'
WHEN '051'
THEN 'GPRS MMS roaming'
WHEN '065'
THEN 'Emergency Call Attempt '
ELSE ''
END call_type_description,
call_type call_type_code,
CASE
WHEN netflag IN ('ON')
THEN 'On net'
ELSE 'Off net'
END eventtype,
CASE
WHEN tariffclass IN ('A')
THEN 'Peak'
ELSE 'Off Peak'
END CLASS
FROM CALL_TRACE_POSTPAID_SEP10
WHERE 1 = 1
AND transdate >= TO_DATE ('01/09/2010', 'DD/MM/YYYY HH24:MI:SS')
AND transdate < TO_DATE ('15/09/2010', 'DD/MM/YYYY HH24:MI:SS') + 1
AND TO_CHAR (transdate, 'HH24:MI:SS') >= '18:43:52'
AND TO_CHAR (transdate, 'HH24:MI:SS') <= '21:50:03'
AND act_duration < 60
AND subno IN ('1111111')
AND contrno = '122333'
AND chargetype IN ('L')
ORDER BY transdate DESC
Appreciate your feedback/suggestions in this regard to proceed further.Please read:
1. On ROWNUM and Limiting Results By Tom Kyte http://www.oracle.com/technetwork/issue-archive/2006/06-sep/o56asktom-086197.html
2. On Top-n and Pagination Queries By Tom Kyte http://www.oracle.com/technetwork/issue-archive/2007/07-jan/o17asktom-093877.html
Edited by: P. Forstmann on 12 janv. 2011 09:54 -
Hi all,
I have a query regarding the Pagination in the table component.I have a table and this table has been paginated with size 5. I am using an ObjectListdataprovider for populating data in table.Here i populate the ObjectList from another page and show it here in another page.Here we can chane the data.when i am clicking on the save it only considering the first 5 values dat is currently showing.This thing happens only when i didn't go the the second page using page navigation buttons.That is it ony saves the data that got focus.Can anyone have any solution?Please help me..
Thanks and Regards
SreeDo you have a message group component on the page to display runtime errors?
Did you check the server log (right-click Deployment Server and choose View Server Log) to see if any errors show up there?
Do you have any table colomn components bound to non-string fields? If so, did you drop the right type of converters on those components? -
Need advice on pagination query
Hello,
I have the following example of a pagination query, but I heard that there might be some drawbacks to this query. Could anyone please let me know any problems that might happen with this? The user will provide inputs for p and q. Thanks.
Select *
From (select rownum as n, * from table order by x, y, z)
Where n between p and qHi,
arizona9952 wrote:
Hello,
I have the following example of a pagination query, but I heard that there might be some drawbacks to this query. Could anyone please let me know any problems that might happen with this? The user will provide inputs for p and q. Thanks.
Select *
From (select rownum as n, * from table order by x, y, z)
Where n between p and qIf there is anything in the SELECT clause along with *, then * has to be qualified by a table name or alias. (See the example below.)
ORDER BY is applied after ROWNUM is assigned. For example, the qub-query might find x values 5, 8 and 3, and assign ROWNUM in that order, so you'd have
x ROWNUM
5 1
8 2
3 3so if you were looking for the 2nd highest, you would get 8.
I would use the analytic ROW_NUMBER function instead of ROWNUM.
WITH got_r_num AS
SELECT x.* -- not just *
, ROW_NUMBER () OVER (ORDER BY x, y, z) AS r_num
FROM table_x
SELECT *
FROM got_r_num
WHERE r_num BETWEEN :p
AND :Q
ORDER BY r_num
;To use ROWNUM, you would need 2 sub-queries. In the first, you would use ORDER BY, in the second, apply ROWNUM, and finally, in the main query, pick the values you wanted.
Maybe you are looking for
-
Hi I am struggeling with a question. I want somwhere to view discs when I burn DVD's and BR's At the moment I have a Sony BR player and a 22" samsung TV, which basicly is ok, but not that big, compared to that my clients watch the same discs on 32+ i
-
Trying to upload the apps and i get an error 49 what does it mean?
trying to upload the apps and I get an unable to upload with a (49) after it, any ideas please?
-
HRMD_A Scheduler is in state "not ready"
I am using IDOC type HRMD_A to upload data for infotype IT0002 & IT0006. The IDOCs go in to status 51 with message 'Scheduler is in state "not ready"' I am able to upload data for other data objects using IDOCs correctly. Please advice how to overcom
-
hello, I use a foreach tag to browse a map, but some ">" are add betwen two items. I would like to know why... here is my code: <c:forEach var="map" items ="${dependency.versions}"> <c:set scope="session" var="project" value="${map.key}" />
-
Compatibility issues CS5 to CC 2014
Hi, We just installed Adobe's CC 2014 versions at school but I haven't installed any yet on my home computer. I asked my students to save a copy in CS5 version so I could look at their files home. There have been some major compatibility issues regar