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
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 ? | 56 Yes | 5 No |
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 |
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 |
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 |
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 |
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 |
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 |
What is ibm db2 client?
How to get Top 10 Salaries from a Table
SI Stud name Subject Marks Pass/Fail 1 Sham Maths 40 P 1 Sham Physics 50 P 1 Sham Bio 20 F 2 Ram Maths 40 P 2 Ram Physics 50 P 2 Ram Bio 60 P For the above data , write the SQL query for the student who passed in all the subjects . For eg : I want the data of only Ram coz he passed all subjects .
What are the three DB2 date and time data types and their associated functions?
What is -904 sql code? How to resolve it?
how to copy the host variables from ps file into cobol program other than include statement
What is an access path?
which is the most efficient tablespace?? a.simple tablespace. b.partitioned tablespace. c.segmented tablespace. d.none of the above. please post answer with the reason.?
How to find primary key of a table in db2?
When the like statement is used?
what are the max. & min. no. of partitions allowed in a partition tablespace?
How do you prepare a COBOL + DB2 program from coading till execution ?