How to resolve the -305 error code in DB2?
And also please let me know, how to resolve the db2 error
codes.

Answers were Sorted based on User's Feedback



How to resolve the -305 error code in DB2? And also please let me know, how to resolve the db2 erro..

Answer / daphne

Before going to the solution, here is the explanation of a
null indicator.

In DB2, a NULL is stored using a special one-byte null
indicator which is attached to every NULLABLE column. If
the column is defined as NULL, then the indicator field is
used to record this. The indicator variable is transparent
to an end user, but must be provided for when programming
in a host language.

A positive value or a value of 0 means the column is not
null and any actual value stored in the column is valid. A
negative value indicates that the column is set to null. If
the value is -2 then the column was set to null as the
result of a data conversion error. The default is null.



There are two reasons for getting -305.

1) As said in the first answer if the table column is
defined as NOT NULL (with no default) and if we try to
insert a null value we get that.
- This should be resolved by making sure the inserted
value is not null. Null indicator cannot be used here since
the column is defined as NOT NULL.


2) A table column is defined as NULL:
The host variable has a not null value. The Null
indicator is not set in the host program, so the null
indicator is defaulted to a negative value.
- This should be resolved by using a null indicator in
the host program and moving the relevant value to the null
indicator.

Is This Answer Correct ?    55 Yes 5 No

How to resolve the -305 error code in DB2? And also please let me know, how to resolve the db2 erro..

Answer / guest

supose, one of ur DB2 table column is defined as NOT NULL,
if u trying to insert null value on that column at that
time , u will get this error.

u can slove this error by handling the null indicator in
ur program.
define null indiactor workign stroage variable with s9(4)
comp.

Is This Answer Correct ?    45 Yes 12 No

How to resolve the -305 error code in DB2? And also please let me know, how to resolve the db2 erro..

Answer / s

If a column contains nulls and you dont include a null
indicator variable in the program, the program receives a
-305 SQLCODE.
Even if no columns allow for nulls, it may be necessary to
use the null indicator to avoid a -305 SQLCODE. For eg, if
AVG(SAL) is computed and ther eare no employees in the
department, the result is null and a null indicator must be
ccoded on the SQL statement to avoid -305.
EXEC SQL SELECT SNAME
INTO :SNAME:SNAME-INDNULL
FROM S
WHERE SN = :SN-IN
END-EXEC
If SNAME has a value, SNAME-INDNULL contains 0.
If SNAME is NULL, SNAME-INDNULL contains -2.

Similarly, Inserting a NULL also required special handling.
If you are not providing a value for SNAME, a -1 can be
moved to the null indicator associated with the SNAME
column:

MOVE -1 to SNAME-INDNULL

EXEC SQL INSERT INTO S
(SN,SNAME,STATUS,CITY) VALUE
(:SN,:SNAME:SNAME-INDNULL,:STATUS,:CITY)
END-EXEC

Is This Answer Correct ?    23 Yes 3 No

How to resolve the -305 error code in DB2? And also please let me know, how to resolve the db2 erro..

Answer / satish29

If you are moving NULL to host variable, -305 error will
get.
check in your db2 table whether NULL values are present or
not.

Is This Answer Correct ?    10 Yes 3 No

How to resolve the -305 error code in DB2? And also please let me know, how to resolve the db2 erro..

Answer / logaa

if the table column is defined as NOT NULL (with no
default) and if we try to insert a null value we get that
we get a different SQLCODE -407

Is This Answer Correct ?    10 Yes 6 No

How to resolve the -305 error code in DB2? And also please let me know, how to resolve the db2 erro..

Answer / yogesh

- 407 : Column in the table is defined as "NOT NULL", but
an INSERT or UPDATE is done to make the column as 'NULL'

-305 : Trying to FETCH or SELECT a null value from the
column of a table to a output host variable, which doesn't
have a null indicator declared for the host variable.

Is This Answer Correct ?    7 Yes 8 No

How to resolve the -305 error code in DB2? And also please let me know, how to resolve the db2 erro..

Answer / vikram and mangesh

The null value is the concept of DB2 and your application
program does not understand the null concept, so to handle
the null value in our application program we use null
indicator.

Null indicator will have following values(depending upon
what values comes from DB2).
0 means the column is not null and any actual value stored
in the column is valid.
-1 means column is set to null.
-2 means column was set to null as the result of a data
conversion error.


in above scenarion if your table contains nullable columns
(means the column can have null values) and in aplication
program you dont mentioned the null indicator,you will get
sql code -305.

For a NOT NULL column there is no need of null indicator as
there cannot be null at any point of time and if you dont
give any value then you will get SQL code -407.

Is This Answer Correct ?    4 Yes 8 No

Post New Answer

More DB2 Interview Questions

What is a clustered index?

1 Answers  


What is filter factor?

2 Answers  


Suppose if I need to update a column, how you do that using cursor?

2 Answers   Verizon,


What is plan in cobol db2?

0 Answers  


Why do we need reorg in db2?

0 Answers  






Explain what a plan is?

3 Answers   CTS,


How to resolve deadlock issue

5 Answers   IBM,


What is db2 purescale?

0 Answers  


When is the skeleton cursor table created?

1 Answers  


How to handle null values in db2

4 Answers  


What is copy pending and check pending in db2?

0 Answers  


How does coalesce work?

0 Answers  


Categories