Pull 20 records for each time [message #646831] |
Mon, 11 January 2016 07:01 |
|
itnagaraj
Messages: 3 Registered: January 2016 Location: Chennai
|
Junior Member |
|
|
How to pull 20 records for each time?.
I have created the stored procedure to display the records in front end.
But client requirement is to pull 20 records for first time and click the next button, we pull the records from next 20 records(21 to 40) to avoid the performance issue.
Klindly provide the solution for this.
Advance thanks.
|
|
|
|
|
Re: Pull 20 records for each time [message #646835 is a reply to message #646834] |
Mon, 11 January 2016 07:13 |
John Watson
Messages: 8929 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
1. I doubt that your users intend to page through 17500000 rows. They would be clicking Next from now until the end of eternity.
2. Why use PL/SDQL when SQL will do?
3. I wish you wouldn't say "record" when you mean "row".
|
|
|
Re: Pull 20 records for each time [message #646836 is a reply to message #646835] |
Mon, 11 January 2016 07:19 |
|
itnagaraj
Messages: 3 Registered: January 2016 Location: Chennai
|
Junior Member |
|
|
Hi John,
This is my stored procedure.
create or replace PROCEDURE GET_MEMBER_DETAILS (p_siteid IN VARCHAR2 DEFAULT NULL,
p_premiumid IN VARCHAR2 DEFAULT NULL,
p_rewardid IN VARCHAR2 DEFAULT NULL,
p_activeflag IN VARCHAR2 DEFAULT NULL,
p_recordset OUT SYS_REFCURSOR) AS
BEGIN
OPEN p_recordset FOR
SELECT M.MEM_ID,
M.EMAIL,
M.PASSWORD,
M.FNAME,
M.LNAME,
M.JOIN_DATE,
M.SOL_ID,
M.PREMIUM_ID,
M.REWARD_ID,
M.EBATES_MERCHANT_GROUP_ID,
M.SITE_ID,
M.PRODUCT_ID,
M.BILL_STATUS_ID,
M.BILL_CYCLE_START_DATE,
M.AUTOLOGIN_KEY,
DECODE(M.ACTIVE_FL, 1, 'True', 'False') as ACTIVE_FL,
S.SITE_NAME
FROM
Member M, SITE S
WHERE
(p_siteid is null or S.SITE_ID = p_siteid)
AND (p_premiumid is null or M.PREMIUM_ID = p_premiumid)
AND (p_rewardid is null or M.REWARD_ID = p_rewardid)
AND (p_activeflag is null or M.ACTIVE_FL = p_activeflag)
AND M.SITE_ID = S.SITE_ID
ORDER BY MEM_ID;
END;
If i am passing all parameter as null, it will return 1,75,00,000 records.
First time i will pull first 20 records, second time next 20 records etc.
How to implement this?
|
|
|
|
|
|
Re: Pull 20 records for each time [message #646840 is a reply to message #646839] |
Mon, 11 January 2016 08:46 |
cookiemonster
Messages: 13920 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
If you're using a ref cursor the correct solution is to get the calling program to fetch only 20 rows at a time as Michel already said.
Ref cursors will only fetch as many rows in a go as you tell them to.
Also this won't work:
garan wrote on Mon, 11 January 2016 14:24
To get next 20 rows
SELECT * FROM EMP WHERE ROWNUM < 41 MINUS SELECT * FROM EMP WHERE ROWNUM < 21
There is no guarantee that oracle will assign rownum to the rows in the same order in those to queries - it probably will but you can't rely on it.
Have a look on AskTom for the correct way to do pagination queries.
|
|
|