IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Random Read in DB2


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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
Reply with quote

Is this what you are looking for:

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
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Error to read log with rexx CLIST & REXX 11
No new posts Generate random number from range of ... COBOL Programming 3
No new posts Random read in ESDS file by using RBA JCL & VSAM 6
No new posts VSAM return code 23 - for a Random read COBOL Programming 4
No new posts ICETOOL to Read records SMF CEF it is... DFSORT/ICETOOL 4
Search our Forums:

Back to Top