Oracle空检查字符串字段 [英] Oracle null check for string field

查看:76
本文介绍了Oracle空检查字符串字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的示例中,为什么在Oracle 11g中除"NAME1"以外的所有结果都为空.

In this below example why other than "NAME1" all giving null as result in oracle 11g.

如果我明确提到空格,则需要空格,否则仅返回null而不是空字符串.请帮助我阐明这一点.

If I mention space explicitly it takes space otherwise null only not empty string.Please help me to clarify this.

在NAME2中,我指定了空白,但仍然为null.

In NAME2 I specify the empty space but still it gives null.

select 
NVL(NAME,' ') AS NAME1,
NVL(NAME,'') AS NAME2,
NVL(NAME,NULL) AS NAME3,
NAME AS NAME4 
from employee

输出:

(空格),null,null,null

(space),null,null,null

推荐答案

在Oracle中,零长度的varchar被视为NULL.

Because in Oracle a ZERO length varchar is treated as NULL.

在您的示例中

NVL(NAME, ' ') AS NAME1 will evaluate to either NAME or ' ' - empty string.
NVL(NAME, '') as NAME2 will evaluate to either NAME or a zero length string

这篇关于Oracle空检查字符串字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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