Page 1 of 1

NULL and SQLCODE -305.

Posted: Mon Jan 25, 2016 4:24 pm
by Krishna singh
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...

Re: NULL and SQLCODE -305.

Posted: Mon Jan 25, 2016 4:34 pm
by zprogrammer
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

Re: NULL and SQLCODE -305.

Posted: Mon Jan 25, 2016 7:44 pm
by nicc
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.

Re: NULL and SQLCODE -305.

Posted: Wed Jan 27, 2016 12:08 pm
by Anuj Dhawan
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.

Re: NULL and SQLCODE -305.

Posted: Tue Jul 26, 2016 1:55 pm
by Krishna singh
Thanks a lot all for your explnation. It has helped.

Re: NULL and SQLCODE -305.

Posted: Tue Jul 26, 2016 2:16 pm
by Anuj Dhawan
Glad, we were helpful.