DB2:不允许“NULL";柱子? [英] DB2: Won't Allow "NULL" column?
本文介绍了DB2:不允许“NULL";柱子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们的应用正在运行的复杂查询的一部分包含以下行:...(内部查询)
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
...
虽然在 MSSQL 和 Oracle DBs 中完全可以,但这种创建具有 null 值的列的语法在 DB2 中是不允许的.从技术上讲,我可以将其更改为:
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,
但这并没有完全相同的含义,可能会损坏我们的计算结果.如何使用其他语法在 DB2 中创建具有空值的列??
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??
推荐答案
DB2是强类型的,所以你需要告诉DB2你的NULL是什么类型的列:
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
...
这篇关于DB2:不允许“NULL";柱子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文