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
 

 

Why select * retrieve only one row

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Mainframe Interview Questions
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    Post subject: Why select * retrieve only one row
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: 3158
Location: Tucson AZ

PostPosted: Sun Jan 21, 2007 6:19 pm    Post subject:
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

Site Director


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

PostPosted: Sun Jan 21, 2007 9:40 pm    Post subject:
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    Post subject: Re: Why select * retrieve only one row
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: 12
Location: Mysore

PostPosted: Sun Jan 21, 2007 11:33 pm    Post subject:
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    Post subject: Re: Why select * retrieve only one row
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    IBMMAINFRAMES.com Support Forums -> Mainframe Interview Questions All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts SQL - select data available in index Nileshkul DB2 3 Mon Jun 26, 2017 1:30 am
No new posts Two Selects in a single select query Rohit Umarjikar DB2 1 Fri Nov 04, 2016 8:46 pm
No new posts Need to retrieve Julian_date Suganya87 DB2 4 Wed Aug 17, 2016 7:27 pm
No new posts Select first 2 group data vice_versa DFSORT/ICETOOL 10 Mon Jun 13, 2016 2:21 pm
No new posts Retrieve current year or month using ... vnktrrd DFSORT/ICETOOL 15 Tue Mar 15, 2016 4:14 pm


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