oracle中的空字符串 [英] empty string in oracle

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

问题描述

当我在数据库表列中插入一个空String时,它看起来像在内部存储为NULL.那么,为什么不能通过完全寻找那个空字符串来选择相应的行呢?

When I insert an empty String in a database table column, it looks like it is internally stored as NULL. So why can I not select the respective row by looking for exactly that empty string?

示例:

insert into mytable (mycolumn,col2,col3) values ('','xyz','abc');

// now there is a row having mycolumn == NULL

select * from mytable where mycolumn='';

// empty :(

我该怎么办?

推荐答案

这是Oracle中的古怪时代(使用默认设置).实际上,Oracle确实将空字符串视为NULL.这包括比较,所以:

This is a weird anachronism in Oracle (using default settings). Oracle does, indeed, treat an empty string as NULL. This includes in comparisons, so:

where mycolumn = ''

与以下相同:

where mycolumn = NULL

这永远不会返回true(NULL <> NULL).

And this never returns true (NULL <> NULL).

我的建议?习惯于显式使用NULL并编写:

My advice? Get used to using NULL explicitly and writing:

where mycolumn is null

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

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