NULL and SQLCODE -305.

RDBMS from IBM.
Previous topicNext topic

Topic Author
Krishna singh
New Member
Posts: 6
Joined: Wed Jan 20, 2016 12:26 am

NULL and SQLCODE -305.

Post by Krishna singh » Mon Jan 25, 2016 4:24 pm

Hi,

In my program Ihave a select statemnet. In that select I am using a a null column. How can I know that I am selecting a null column. If I check only SQLCODE -305, will that be fine. If it is not, why it is not coded this way...




zprogrammer
Global Moderator
Global Moderator
Posts: 605
Joined: Wed Nov 20, 2013 11:53 am
Location: Mars
Zodiac: Libra

Re: NULL and SQLCODE -305.

Post by zprogrammer » Mon Jan 25, 2016 4:34 pm

You might also need to follow your company standard procedure for all the validations that needs to be done.. Talk to your team or check the existing programs and that should answer your question


zprogrammer


nicc
Global Moderator
Global Moderator
Posts: 597
Joined: Wed Apr 23, 2014 8:45 pm

Re: NULL and SQLCODE -305.

Post by nicc » Mon Jan 25, 2016 7:44 pm

If NULL can be returned instead of a column value then you should be coding a Null indicator variable alongside the variable that would have the value returned in it if there was a value to return.


Regards
Nic

User avatar

Anuj Dhawan
Founder
Posts: 2624
Joined: Sun Apr 21, 2013 7:40 pm
Location: Mumbai, India
Zodiac: Sagittarius

Re: NULL and SQLCODE -305.

Post by Anuj Dhawan » Wed Jan 27, 2016 12:08 pm

Krishna singh wrote:Hi,

In my program Ihave a select statemnet. In that select I am using a a null column. How can I know that I am selecting a null column. If I check only SQLCODE -305, will that be fine. If it is not, why it is not coded this way...
The short answer is - you can do that.

The long answer is - it depends and it depends on multiple inputs; one of which is - does the short answer suffice to your needs? By definition SQLCODE -305 is:
-305
THE NULL VALUE CANNOT BE ASSIGNED TO OUTPUT HOST VARIABLE NUMBER position-number BECAUSE NO INDICATOR VARIABLE IS SPECIFIED
Explanation

A FETCH, SELECT, VALUES INTO, or SET assignment statement resulted in the retrieval of a null value to be inserted into the output host variable, designated by entry number 'position-number' of the output SQLDA, for which no indicator variable was provided. An indicator variable must be supplied if a column returns a null value.

System action

The statement cannot be processed. No data was retrieved.

Programmer response

Examine the definition of the table that is the object of the statement and correct the application program to provide indicator variables for all host variables into which null values can be retrieved. This includes host variables for columns which can contain null values and host variables which receive the results of aggregate functions whose result table could be empty.
Per the definition - if you consider this "the null value cannot be assigned to output host variable number position-number because no indicator variable is specified" and acceptable test-condition, well, you can show an appropriate message and terminate the program. However, in other world and the one which has been accepted by the larger group of programmer, we tend to take action based on the NULL indicator as nicc and Pandora-Box has also indicated to.


Thanks,
Anuj

Disclaimer: My comments on this website are my own and do not represent the opinions or suggestions of any other person or business entity, in any way.


Topic Author
Krishna singh
New Member
Posts: 6
Joined: Wed Jan 20, 2016 12:26 am

Re: NULL and SQLCODE -305.

Post by Krishna singh » Tue Jul 26, 2016 1:55 pm

Thanks a lot all for your explnation. It has helped.



User avatar

Anuj Dhawan
Founder
Posts: 2624
Joined: Sun Apr 21, 2013 7:40 pm
Location: Mumbai, India
Zodiac: Sagittarius

Re: NULL and SQLCODE -305.

Post by Anuj Dhawan » Tue Jul 26, 2016 2:16 pm

Glad, we were helpful.


Thanks,
Anuj

Disclaimer: My comments on this website are my own and do not represent the opinions or suggestions of any other person or business entity, in any way.

Previous topicNext topic

Return to “IBM DB2.”