MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

INSERT INTO ... SELECT & Pagination logic

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
hellohatim
Beginner


Joined: 12 Apr 2007
Posts: 28
Topics: 7

PostPosted: Mon Dec 22, 2008 9:55 am    Post subject: INSERT INTO ... SELECT & Pagination logic Reply with quote

Hi All,

I am working on DB2 (ver 8 I guess!) z/OS Stored Procedures and had a requirement to insert data from one table to another. I want to select the last ten rows of the query and insert it in the table. I tried giving a nested SELECT query inside INSERT SQL statement but it does not accept "FETCH FIRST 10 ROWS ONLY". As of now I have to fetch all the 10 rows in Working Storage variables and then insert them seperately into the table.

The insert statement I tried was something like this...

Code:
INSERT INTO SESSION.TEMP (A, B, C, D)
SELECT A, B, C, D
FROM   P72.PARTNER_MERCHANT
WHERE  ...


This does not work if I add "ORDER BY A DESC FETCH FIRST 10 ROWS ONLY" to the nested SELECT Query. The SELECT query with FETCH FIRST 10 works well standalone. Believe there is no such thing as ROW_NUMBER() as well to help me achieve this.

- Is there a way to achieve the desired result in a single SQL query?

- In larger context, this piece of code is for pagination logic for retrieving search results to be displayed on the web page. Currently we are populating a global temporary table with 10 records each (which is the size of the page). A cursor to this table with SELECT * is openened and the same is then passed on as a result set (to Java front end). Every time the user moves to the next page, the query is re-executed and then table is dropped and refilled with the new contents. Is there a better way to achieve such pagination logic (either on the SP or Java side)? I read about scrollable cursors, but as of now I am not aware about its exact working. The search results can run into thousands of rows ... efficiency & speed is also a factor we would need to consider.

Regards,
Hatim
_________________
-Hatim M P
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group