Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How to generate a Seq/Row counter for each row in a cursor?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
Ramanan-R

New User


Joined: 21 Mar 2007
Posts: 66
Location: Chennai, Tamilnadu, India

PostPosted: Sun Aug 21, 2011 9:29 pm    Post subject: How to generate a Seq/Row counter for each row in a cursor?
Reply with quote

Hi All,

The requirement is to generate a unique Sequence/Row counter from 1 auto incremented by 1 for each row retrieved from a cursor.
Back to top
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Sun Aug 21, 2011 10:11 pm    Post subject:
Reply with quote

why make db2 do the work?
when you open the CURSOR intialize a working/storage counter.
after each successful fetch ADD 1 to the counter.

if your db2 supports row_number, look up the syntax in the manual.

sounds like a class project, instead of a requirement.

you should have posted this question in our companion website for
beginners and people who can not read manuals.
Back to top
View user's profile Send private message
shivaganeshaa

New User


Joined: 11 Aug 2005
Posts: 14
Location: chennai

PostPosted: Sun Aug 21, 2011 10:56 pm    Post subject:
Reply with quote

Define sequence object in DB2 , and that will give you the increment directly every time you access that variable.
Back to top
View user's profile Send private message
Ramanan-R

New User


Joined: 21 Mar 2007
Posts: 66
Location: Chennai, Tamilnadu, India

PostPosted: Mon Aug 22, 2011 7:51 am    Post subject:
Reply with quote

Actually i need to code this in a stored procedure which would be called by Java through DB2 connect and hence would be just using Open cursor without fetch statement...
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Mon Aug 22, 2011 8:43 am    Post subject:
Reply with quote

Hello,

Then get the row_number in the other code, not the stored procedure?
Back to top
View user's profile Send private message
shivaganeshaa

New User


Joined: 11 Aug 2005
Posts: 14
Location: chennai

PostPosted: Mon Aug 22, 2011 8:57 am    Post subject: Reply to: How to generate a Seq/Row counter for each row in
Reply with quote

At any rate you need to get in touch with DBA to define Data Base object which is type SEQUENCE OBJECT.

Something as below

CREATE SEQUENCE orders_seq AS INT
START WITH 1
INCREMENT BY 1
MINVALUE 1
NO MAXVALUE
NO CYCLE
NO CACHE
ORDER



If possible give more info, on what do you mean you say OPEN cursor and not fetch it and by Java thru DB2 Connect.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Mon Aug 22, 2011 9:46 am    Post subject:
Reply with quote

Hello,

I believe this will not do what Ramanan-R wants. . .

I believe the goal is to get the relative row number of the rows as each is returned. This might not be the same as the "sequence" number.

Possibly i misunderstand.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Getting -504 Cursor Name GTT-ARTS-CUR... Robin Sulsona DB2 2 Fri Mar 17, 2017 1:43 am
No new posts TSO or command line utility to genera... kishpra JCL & VSAM 3 Thu Mar 09, 2017 1:11 am
No new posts Release of Adabas Cursor mohitsethi All Other Mainframe Topics 1 Mon Feb 06, 2017 8:36 pm
No new posts Updating Cursor row withour using FOR... chandan.inst DB2 15 Tue Nov 08, 2016 11:17 am
No new posts Variable for cursor names ravikumar15 DB2 5 Sun Jul 17, 2016 7:08 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us