Hi,
Can any one tell me how to solve null indicator sqlcode - 305?
Thanks.
How to solve null indicator sqlcode - 305?
-
- New Member
- Posts: 8
- Joined: Mon Feb 22, 2016 5:53 pm
Re: How to solve null indicator sqlcode - 305?
Hello.
A null column is one which can have no value. In order to handle a nullable column, an additional field needs to be defined which will allow DB2 to provide an indication as to whether the column is, in fact, null. This takes the form of a halfword integer (i.e. PIC S9(4) COMP) which needs to be defined as a host variable. For example,
When you specify the field in an SQL statement, both variables will be specified (note that there is no comma between the output field and the indicator):
Upon execution, you will either get back the value of the column and the null indicator, or just the value of the null indicator. If the null indicator is negative, then the column is null (the host variable for the value will be unchanged, so don't use it). Zero indicates that the field has a value.
The same thing applies when using null columns in statements such as FETCH, INSERT, UPDATE, or DELETE. Where a predicate for a nullable column is using a value specified in a host variable, the indicator variable needs to be specified there too:
Any time that you are supplying a value rather than expecting one to be returned, the null indicator will need to be initialised correctly by the program.
If you are using tables which have a DCLGENed member available for them (which I would recommend as it saves a lot of work), you should find that any null columns automatically have a null indicator field defined for them.
A null column is one which can have no value. In order to handle a nullable column, an additional field needs to be defined which will allow DB2 to provide an indication as to whether the column is, in fact, null. This takes the form of a halfword integer (i.e. PIC S9(4) COMP) which needs to be defined as a host variable. For example,
Code: Select all
EXEC SQL BEGIN DECLARE SECTION.
01 TEST-COLUMN PIC X(20).
01 TEST-COLUMN-IND PIC S9(4) COMP.
EXEC SQL END DECLARE SECTION.
Code: Select all
EXEC SQL
SELECT TEST_COLUMN
INTO :TEST-COLUMN :TEST-COLUMN-IND
WHERE TEST-KEY = '12345'
END-EXEC.
The same thing applies when using null columns in statements such as FETCH, INSERT, UPDATE, or DELETE. Where a predicate for a nullable column is using a value specified in a host variable, the indicator variable needs to be specified there too:
Code: Select all
WHERE TEST-COLUMN = :TEST-COLUMN :TEST-COLUMN-IND
If you are using tables which have a DCLGENed member available for them (which I would recommend as it saves a lot of work), you should find that any null columns automatically have a null indicator field defined for them.
Create an account or sign in to join the discussion
You need to be a member in order to post a reply
Create an account
Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute