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
 

 

Random Read in DB2

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

New User


Joined: 08 Sep 2006
Posts: 9

PostPosted: Thu Dec 14, 2006 3:51 pm    Post subject: Random Read in DB2
Reply with quote

Hi all,
is it possible to fetch random rows in a table without knowing any information about table, you only know the name.
for example in a table MYTABLE display first , fifth, seventh rows.

If it is possible please let me know.

Also tell me that how to fetch a row in table using indexes.
Can we fetch a row using index created on primary key.


Arun.
Back to top
View user's profile Send private message

MFRASHEED

Active User


Joined: 14 Jun 2005
Posts: 186
Location: USA

PostPosted: Thu Dec 14, 2006 8:48 pm    Post subject: Re: Random Read in DB2
Reply with quote

Is this what you are looking for:

http://ibmmainframes.com/viewtopic.php?t=15735&highlight=
Back to top
View user's profile Send private message
userarun

New User


Joined: 08 Sep 2006
Posts: 9

PostPosted: Fri Dec 15, 2006 5:46 pm    Post subject: Re: Random Read in DB2
Reply with quote

@MFRASHEED

Thanks for that , this is the thing i 'm looking for.

FETCH ROWSET STARTING AT
ABSOLUTE 5 FOR 1 ROW

would this option return the fifth row of the table.
If u give me an example containing both declaring and fetching cursor then that would be best.

Also tell me that can we fetch any row using indexes?

with regards,
Arun
Back to top
View user's profile Send private message
MFRASHEED

Active User


Joined: 14 Jun 2005
Posts: 186
Location: USA

PostPosted: Sat Dec 16, 2006 2:44 am    Post subject: Re: Random Read in DB2
Reply with quote

Quote:

would this option return the fifth row of the table.


Looks like it will, try it out.


Quote:


If u give me an example containing both declaring and fetching cursor then that would be best.


Links provided in previous post also have examples, just scroll down to the end of manual.

Quote:

Also tell me that can we fetch any row using indexes?



If a table has index, Db2 will always try to use the index.
If a table has multiple indexes, Db2 optimizer will again try to use fastest path to access data. We need to make sure that Runstats,Reorg and Rebind are schedule to run depending to activity on table. Runstats keeps stats on table accurate and helps optimizer determine best/fastest path to data.

Probably good SQL coding practive would be to code the WHERE clause of SQL to have indexed column with '=' first, then index columns with >,<, or Between next, then non-indexed column's with '=' and non-indexed columns with <,> , Between etc.

To get any idea filtering and access path SQL would take, execute EXPLAIN or Enhanced Explain on SQL.
Back to top
View user's profile Send private message
userarun

New User


Joined: 08 Sep 2006
Posts: 9

PostPosted: Sat Dec 16, 2006 5:25 pm    Post subject: Re: Random Read in DB2
Reply with quote

@ MFRASHEED

Thanx for this help. This will help me a lot.
i'll contact u if get any problem. Thanx.
With regards,
Arun.
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 READ A PACKED "NEGATIVE" FI... jdesouza CA Products 3 Tue May 02, 2017 11:43 pm
No new posts Read of TDQ fails in LENGERR Tracy Hansen CICS 10 Wed Apr 05, 2017 12:10 am
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts CICS VSAM RLS READ akodakka CICS 3 Tue Oct 04, 2016 3:09 pm
No new posts Random Password (in string format) ge... ezhavendhan COBOL Programming 10 Mon Aug 29, 2016 3:18 pm


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