DB2:不允许“ NULL”;柱? [英] DB2: Won't Allow "NULL" column?

查看:120
本文介绍了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
...

这种在DB2中不允许使用具有 null 值的列的语法,尽管在此完全可以 MSSQL Oracle 数据库。
从技术上讲,我可以将其更改为:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆