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

Why select * retrieve only one row


IBM Mainframe Forums -> Mainframe Interview Questions
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
shrikanth_m
Currently Banned

New User


Joined: 19 Jan 2007
Posts: 5
Location: bangalore

PostPosted: Sun Jan 21, 2007 5:53 pm
Reply with quote

why select * retrieve only one row, where as cursor retrieves multiple rows? is there any specific reason for that? can some body help me out !!

Aprreciate help from anyone!

Thanks
Shrikanth! icon_lol.gif
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Sun Jan 21, 2007 6:19 pm
Reply with quote

As far as I know, "*" just retrieves all columns, it is the "where" that retrieves the rows.
I can't access the command reference (IBM's site is having a "Internal Server Error") to see what kind of retrieval occurs without a "where" clause - or even if that is allowed.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Sun Jan 21, 2007 9:40 pm
Reply with quote

Hello,

Quote:
why select * retrieve only one row, where as cursor retrieves multiple rows? is there any specific reason for that?


The reason is because that is the way DB2 is implemented. To "scroll" thru multiple rows in your program, you use a cursor.
Back to top
View user's profile Send private message
sachin_star3
Warnings : 1

New User


Joined: 30 Sep 2006
Posts: 78
Location: pune

PostPosted: Sun Jan 21, 2007 10:25 pm
Reply with quote

shrikanth_m wrote:
why select * retrieve only one row, where as cursor retrieves multiple rows? is there any specific reason for that? can some body help me out !!

Aprreciate help from anyone!

Thanks
Shrikanth! icon_lol.gif


======================================
HI SHRIKANT
ANSWER:
THE CURSOR IS A CONTROL STRUCTURE , USING CURSOR
THREE STEP: 1] OPEN CUSOR:- IT LOCATE THE POINTER TO FIRST ROW AND IF GROUP BY OR ORDER BY USED THEN IT BUILTS THE RESULTANT TABLE ALSO
2] FETCH CURSOR: IT FETCHES THE ROW 1 BY ONE FROM RESULTANT TABLE
3] CLOSE CURSOR
SO WHEN CURSOR IS FIRST ROW FETCH CURSOR SHOW IT THNIT FETCHES SECOND AND GOING ON --------- BUT WE GET ALL ROWS IN SPPOL AREA BECAUSE I. E FINAL RESULT
AND YOUR QUESTION IS WHY NOT POSSIBLE WITH SELECT*
BECAUSE IT NOT SAVE AND LOCATE THE POSITION AND THERE NO STEPS SO YOU CANT NOT GET RESULT

I THINK IN ABOVE DISCUSSION ONE QUESTION DEFINETLY ARISE YOUR MIND THAT WHY IT IS POSSIBLE IN SPUFI,QMF?
ANSWER:
BECAUSE QMF,SPUFI DYANMICALLY RUN THE SQL QUERY--SET AT TIME
BUT USING FILE MEANS YOU HAVE TO FOLLOW THE BATCH PROCEESING RULE SO IN BATCH THE READ A RECORD/ROW AT A TIME
SO IT IS NOT POSSIBLE WITH SELECT * BECAUSE IT WORK FOR SET AT TIME
SO YOU NEED PALNING SO CURSOR COMES IN PICTURE
I HAVE MENTION THE DETAILS IN ABOVE PARAGRAPH.

SHURE!
FROM- SACHIN BORASE
PUNE
***EMail ID REMOVED... Use CODE tag to include mail id***
----------------------------------------------------------------------------
Back to top
View user's profile Send private message
sundar28

New User


Joined: 30 Jul 2005
Posts: 11
Location: Mysore

PostPosted: Sun Jan 21, 2007 11:33 pm
Reply with quote

Quote:
why select * retrieve only one row, where as cursor retrieves multiple rows? is there any specific reason for that?


DB2 operates on tables and results in another table.
The result table may consist of one are any number of rows depending on the "WHERE" clause.

The COBOL compiler can not handle the table as a single data element.
It can process only one row at a time.
Cursors are used to feed COBOL one row at a time.

It is the inability of the COBOL that we need Cursors.

Note: COBOL* is a 3rd Generation Language and SQL is 4th generation language.

*It is not only COBOL but also other languages like C, C++
Back to top
View user's profile Send private message
ashish_setia
Currently Banned

New User


Joined: 19 Jan 2007
Posts: 3
Location: noida

PostPosted: Mon Jan 22, 2007 1:22 am
Reply with quote

hey,
this is quit simple actually COBOL is a record level programming language which actually process only one record at a time so if ur trying to get more than one record from database using select * ,,,, it can only retrieve u asingle row at atime..

about using cursor..
actually when we declare a cursor and then open it actually make RESULT TABLE (which is having all the records u have selected using SELECt *) and put that table in main memory (not visible to us).
and cursor will do the same thing that cobol program was doing ..
selecting one roe at a time but it can dynamically go to thr result table again a nd again an willa ctually write all ur result of SELECT * into the spool or into the file..
i suppose the concept would b a bit clear to u now

Ashish setia
shrikanth_m wrote:
why select * retrieve only one row, where as cursor retrieves multiple rows? is there any specific reason for that? can some body help me out !!

Aprreciate help from anyone!

Thanks
Shrikanth! icon_lol.gif
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 -> Mainframe Interview Questions

 


Similar Topics
Topic Forum Replies
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Using Java/C/C++ to retrieve dataset ... Java & MQSeries 6
No new posts SELECT from data change table DB2 5
No new posts Select two different counts from SQL... DB2 6
No new posts Select a DB2 value in a specific deci... DB2 4
Search our Forums:

Back to Top