Db2 Sql Error Sqlcode 305
Contents |
In DB2, the columns defined as NULL needs to be handled carefully else it will throw null exception error, in order to over come
Db2 Sql Error Sqlcode 104 Sqlstate 42601
this error data type can be handled by using null indicator. NULL is db2 sql error sqlcode 206 sqlstate 42703 stored using a special one-byte null indicator that is "attached" to every nullable column. If the column is db2 sql error sqlcode 302 sqlstate 22001 set to NULL, then the indicator field is used to record this. Using NULL will never save space in a DB2 database design - in fact, it will always http://www.ibm.com/support/knowledgecenter/SSEPEK_11.0.0/codes/src/tpc/n305.html add an extra byte for every column that can be NULL. The byte is used whether or not the column is actually set to NULL. The indicator variable is transparent to an end user Consider below Table : Create Table SAMP_TAB SN CHAR (10) SNAME CHAR (10) STATUS CHAR (2) NOT NULL BY DEFAULT CITY CHAR (10) NOT http://mainframestutor.in/305-db2-null-indicator/ NULL Note :: Unless you specify NOT NULL, the default is to allow for NULL In above table SN and SNAME columns holds null values by default, in order to handle these null variables we need to have NULL-INDICATORS declares in the Program as S9(4) comp variable (A indicator variable is shared by both the database manager and the host application. Therefore, this variable must be declared in the application as a host variable, which corresponds to the SQL data type SMALLINT) Let us declare the Null indicators for above two variables in application program as 02 SNAME-INDNULL S9(4) comp 05 SN-IN S9(4) comp What values Null indicators will hold : ‘-1’ : Field is having NULL value ‘ 0’ : Field is Not NULL value ‘-2’ : Field value is truncated How /Why to handling Null Values: When processing INSERT or UPDATE… statements, the database manager checks the null-indicator variable, if one exists. If the indicator variable is negative, the database manager sets the target column value to null, if nulls are allowed else it throws sql erro
MainFrame >> DB2 Suggest New Category How to resolve the -305 error code in DB2? And also please let me know, how to resolve the db2 error codes. Question Posted / viswanatha reddy 7 Answers 42215 Views TCS, I also Faced E-Mail Answers Answers were http://www.allinterview.com/showanswers/13618/resolve-305-error-code-db2-and-also-please-let-know-codes.html 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 db2 sql 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 db2 sql error 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 ? 53 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 ? 44 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.