Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DB2: Won't Allow "NULL" column?

Tags:

sql

db2

Part of a complex query that our app is running contains the lines: ...(inner query)

SELECT ... NULL as column_A, NULL as column_B, ... FROM ... 

This syntax of creating columns with null values is not allowed in DB2 altough it is totally OK in MSSQL and Oracle DBs. Technically I can change it to:

'' as column_A, '' as column_B,  

But this doesn't have exactly the same meaning and can damage our calculation results. How can I create columns with null values in DB2 using other syntax??

like image 274
GyRo Avatar asked Mar 24 '10 16:03

GyRo


People also ask

How do you handle a null in DB2 query?

To test for the existence of nulls, use the special predicate IS NULL in the WHERE clause of the SELECT statement. You cannot simply state WHERE column = NULL. You must state WHERE column IS NULL. It is invalid to test if a column is <> NULL, or >= NULL.

IS NOT NULL function in DB2?

The IS NULL condition is satisfied if the column contains a null value or if the expression cannot be evaluated because it contains one or more null values. If you use the IS NOT NULL operator, the condition is satisfied when the operand is column value that is not null, or an expression that does not evaluate to null.

How do you change a column null to not null in DB2?

If you have a column that does not allow the null value and you want to change it to now allow the null value, use the DROP NOT NULL clause. If you have a column that allows the null value and you want to prevent the use of null values, use the SET NOT NULL clause.

WHAT IS null value in Cobol DB2?

A null value is a special value that Db2 interprets to mean that no data is present. If you do not specify otherwise,Db2 allows any column to contain null values. Users can create rows in the table without providing a value for the column. Using the NOT NULL clause enables you to disallow null values in the column.


1 Answers

DB2 is strongly typed, so you need to tell DB2 what kind of column your NULL is:

select     ...    cast(NULL as int) as column_A,    cast(NULL as varchar(128)) as column_B,    ... FROM    ... 
like image 59
Ian Bjorhovde Avatar answered Sep 21 '22 10:09

Ian Bjorhovde