View previous topic :: View next topic
|
Author |
Message |
chandan.inst
Active User
Joined: 03 Nov 2005 Posts: 275 Location: Mumbai
|
|
|
|
Hi All,
I am aware that it's not advisable to use Select * in Cursor.
But can we code Select * while declaring a cursor.
Also if we specify Select * in a cursor then do we need to specify all Host variables corresponding to Columns of the table or there any other way so that we can get all columns values in a group variables.
E.g. My table is having 40 columns and I am mentioning Select * in cursor then do I need to mention 40 Host variable in INTO clause of FETCH statement or by any way the column values will be fetched in group variable..
Thanks in advance
regards,
Chandan |
|
Back to top |
|
|
Succor
New User
Joined: 20 Feb 2009 Posts: 96 Location: Bangalore :)
|
|
|
|
Yes you can give Select * in Declare statement , instead of writing each and every Column name in the Fetch clause ..use the DCLGEN name in the FETCH INTO clause.I think you must be aware why SELECT * is not advisable. |
|
Back to top |
|
|
VivekKhanna
New User
Joined: 09 Feb 2009 Posts: 57 Location: India
|
|
|
|
I am not sure, but I guess Group-Vairable-Name can be used inplace of using 40 Host-Variables. Again, agreeing to the above remarks by Succor, you should know the consequences of using the SELECT * statement. |
|
Back to top |
|
|
Ketan Varhade
Active User
Joined: 29 Jun 2009 Posts: 197 Location: Mumbai
|
|
|
|
if there is such requirement that u require all the column in the program one of the better way is to unload the table and then process the file. This will save the CPU mins as compared to processing it using DB2
Yes u can unload using select * and can get it into the DCLGEN variable. |
|
Back to top |
|
|
chandan.inst
Active User
Joined: 03 Nov 2005 Posts: 275 Location: Mumbai
|
|
|
|
Hi all,
Thanks for the replies..
I am aware of the consequences of using Select * in Cursor..
I want to use it for single time so just wanted to know can I use the group variable name instaed of mentioning all Host variables..
Regards,
Chandan |
|
Back to top |
|
|
chandan.inst
Active User
Joined: 03 Nov 2005 Posts: 275 Location: Mumbai
|
|
|
|
Hi All,
I tried the abovve query but its givin -303 at Run time
Can anyone plz help me out how to give Null indicators for the columns if I am using Select * or I dont have any other option otherr than coding a column individually
Regards,
Chandan |
|
Back to top |
|
|
Ketan Varhade
Active User
Joined: 29 Jun 2009 Posts: 197 Location: Mumbai
|
|
|
|
Hi
Quote: |
A VALUE CANNOT BE ASSIGNED TO OUTPUT HOST VARIABLE NUMBER position-number BECAUSE THE DATA TYPES ARE NOT COMPARABLE. |
This what is -303 comes for.
Please Verify that table definitions are current and that the host variable has the correct data type.
Hope this help |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
why do you want to worry about NULL-INDICATORS?
RT FM - it is free-- learn what a -303 SQLCODE means. |
|
Back to top |
|
|
chandan.inst
Active User
Joined: 03 Nov 2005 Posts: 275 Location: Mumbai
|
|
|
|
Hi Ketan,
I am aware of the SQLcode its giving that error as Ia m having Null-indicators under same group variable, so its assiging value to the Nill indicator and giving -303
So I want to know how to code Select * exactly in embedded SQL
regards,
Chandan |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Quote: |
Please Verify that table definitions are current and that the host variable has the correct data type |
unnecessary if the OP was not so lazy. With ISPF editing features and EDIT MACROs, it is so easy to populate an sql statement with all the column names for both the select and the into phrase.
yeah, it is quicker type SELECT * /FETCH INTO GROUP.
But if you do not know what you are doing, you are going to spend 2 days debugging BS instead of writing proper sql in the first place. |
|
Back to top |
|
|
Ketan Varhade
Active User
Joined: 29 Jun 2009 Posts: 197 Location: Mumbai
|
|
|
|
Modify\Change the DCL gen variable and then try again |
|
Back to top |
|
|
Ketan Varhade
Active User
Joined: 29 Jun 2009 Posts: 197 Location: Mumbai
|
|
|
|
Hi Dick,
Even in my earlier post I tried saying that only but the requirement was so , that’s why I recommended that |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Ketan, I was not disagreeing with you.
The OP obviously has little knowledge of DB2 and is creating problems for himself while trying to be slick.
I have never seen a DCLGEN'd copybook that lumps the NULL-INDICATORs in the same group as the row structure. Sounds to me as if the COPYBOOK is as poorly generated as the requirement. |
|
Back to top |
|
|
chandan.inst
Active User
Joined: 03 Nov 2005 Posts: 275 Location: Mumbai
|
|
|
|
Hi Dick,
I guess people have interpreted my issue in wrong sense..
Still I am not getting clear idea what exactly the solution..
This might be due to lack of my knowledge in DB2
My concern is can I select columns in a group variable and if one of my column having null values then how to handle it if I am using group variable as a host variable
E.g. I am coding like below
EXEC SQL
select *
into :ws-group-variable
END-EXEC.
This is working fine if there is no null value in any of the columns
My question was how to handle above code if there is null value in any one of the column..
If I try like
EXEC SQL
select *
into :ws-group-variable
:ws-group-variable-null
END-EXEC.
It does not work and gives an error
and if there is no solution for this then I am aware that I need to code all columns in SELECT as well as in INTO clause with null indicators
I will be very thankful to you if you give solution for this and it will help me to enhance my knowledge..
Regards,
Chandan |
|
Back to top |
|
|
Ketan Varhade
Active User
Joined: 29 Jun 2009 Posts: 197 Location: Mumbai
|
|
|
|
Hi Chandan,
Could you tell us why and for what condition you are coding select *
istead of writing all the column names?
I mean what is your requirement that need to stick to select *? |
|
Back to top |
|
|
chandan.inst
Active User
Joined: 03 Nov 2005 Posts: 275 Location: Mumbai
|
|
|
|
Hi Ketan,
I need to select all columns of a table for a particular requirement and its going to be a one time job..
this table having around 150 columns and as its going to be one time job I wanted save the coding efforts for 150 column names,thier host variable names..
If I can't check Null Indicators when I use SELECT * then I dont have other option than coding all columns..
So I have started this post to get if there is any solution apart from coding all columns..
Regards,
Chandan |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1306 Location: Vilnius, Lithuania
|
|
|
|
chandan.inst wrote: |
I will be very thankful to you if you give solution for this and it will help me to enhance my knowledge.. |
There is one very simple rule to enhance your knowledge regarding this:
Never ever use SELECT * in embedded SQL! |
|
Back to top |
|
|
chandan.inst
Active User
Joined: 03 Nov 2005 Posts: 275 Location: Mumbai
|
|
|
|
Hi Prino..
I am very well aware of this rule and I ahve mentioned it in my earlier post..
I just wanted to know is there any way to solve my issue |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
Quote: |
this table having around 150 columns and as its going to be one time job I wanted save the coding efforts for 150 column names,thier host variable names..
If I can't check Null Indicators when I use SELECT * then I dont have other option than coding all columns..
So I have started this post to get if there is any solution apart from coding all columns..
|
Quote: |
I just wanted to know is there any way to solve my issue |
OK .. You tried
by now You should have understood that You cannot do it
what is that is not clear in the replies You got
what else do You want from us
You started this topic on August 13
if You had coded 6 :<destination_variables> and 6 :<null_indicator_variables>
every working day You would have been finished for now
stop wasting everybody's time |
|
Back to top |
|
|
|