SQL之NULL值的几种处理方式
1、创建测试表:
drop table if exists tab_null_operator;
create table tab_null_operator as
select 1 as id,'chavin' as name union all
select 2 as id,'nope' as name union all
select 3 as id,'' as name union all
select 4 as id,'' as name union all
select 5 as id,null as name union all
select 6 as id,null as name union all
select 7 as id,' ' as name union all
select 8 as id,' ' as name union all
select 9 as id,' ' as name union all
select 10 as id,' ' as name
;
2、查看数据:
mysql> select * from tab_null_operator;
+----+--------+
| id | name |
+----+--------+
| 1 | chavin |
| 2 | nope |
| 3 | |
| 4 | |
| 5 | NULL |
| 6 | NULL |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
+----+--------+
10 rows in set (0.00 sec)
小结:从结果我们可以看出,id in (5,6)的两个值是null,id in (1,2)的是字符串,id in (3,4,7,8,9,10)从结果看均是空字符串,实际id in (3,4)是空字符串,id in (7,8)是单个空格字符串,id in (9,10)是\t字符串。
3、查询name为null的记录:
mysql> select * from tab_null_operator where name is null;
+----+------+
| id | name |
+----+------+
| 5 | NULL |
| 6 | NULL |
+----+------+
2 rows in set (0.00 sec)
小结:可以看到只有id in (5,6)的记录name字段才是真正的null。
4、查询name为''的记录信息:
mysql> select * from tab_null_operator where name = '';
+----+------+
| id | name |
+----+------+
| 3 | |
| 4 | |
| 7 | |
| 8 | |
+----+------+
4 rows in set (0.00 sec)
小结:可以看到我们输入的以空格为字符串的值都表现为空字符串。然后\t字符串的缺没有筛选出来。
5、查询\t字符串的数据:
mysql> select * from tab_null_operator where name = ' ';
+----+------+
| id | name |
+----+------+
| 9 | |
| 10 | |
+----+------+
2 rows in set (0.00 sec)
SQL之NULL值的几种处理方式的更多相关文章
- 让索引包含null值的两种方法
1. 把有NULL值的列与一个常数,或者一个带有not null约束的列一同索引 create index ind_01 on t01(col01,1); 或者 create index ind_01 ...
- SQL中NULL值
SQL的表达式,除了IS NULL和NOT NULL以外,只要出现NULL值结果都为FALSE 简单的例子: SELECT * FROM table WHERE name!='abc' 只要name值 ...
- SQL Server NULL值用法及处理详解
用法如下: 1.如果表中的某个列是可选的,那么我们可以在不向该列添加值的情况下插入新记录或更新已有的记录,这意味着该字段将以 NULL 值保存. 2.NULL 用作未知的或不适用的值的占位符. 3.定 ...
- SQL SERVER NULL值和连接注意问题
联接表的列中的 null 值(如果有)互相不匹配.如果其中一个联接表的列中出现空值,只能通过外部联接返回这些空值(除非 WHERE 子句不包括空值). 下面的两个表中,每个表中要参与联接的列中均包 ...
- sql 将Null 值转化成空字符串
当Null + 任何字符串时,都等于Null. 因些用函数IsNull(字段名,''),如果字段名中的值是Null时,那么这个字段名的值是''. 例如::select code + IsNull('- ...
- sql处理null值
IFNULL(expr1,expr2) 如果expr1不是NULL,IFNULL()返回expr1,否则它返回expr2.IFNULL()返回一个数字或字符串值. select (case when ...
- magento 列表页显示产品属性值的几种调用方式
之前有人提到要在列表显示一些特定的属性,除了自带的名字,价格等.因为列表页和产品页都有一个同名的产品对象:$_product,而在产品页,$_product是直接可以用$_product->ge ...
- SQL 多表查询的几种连接方式
--创建数据库 create database GoodsSystem go --使用数据库 use GoodsSystem go --创建商品类型表 create table GoodsType ( ...
- SQL NULL 值【摘自W3C】
SQL NULL 值 本章讲解 IS NULL 和 IS NOT NULL 操作符. NULL 值是遗漏的未知数据.默认地,表的列可以存放 NULL 值. 如果表中的某个列是可选的,那么我们可以在不向 ...
随机推荐
- 安装scala
Linux 环境 安装 下载的scala linux 压缩包放在目录 "/usr/scala “下 解压 tar -zxvf scala-2.11.8.tgz 再配置环境, 编辑文件 ”vi ...
- 递归 - Leetcode 110 判断二叉树是否为平衡二叉树
110. Balanced Binary Tree Given a binary tree, determine if it is height-balanced. For this problem, ...
- unity发布的WebGL部署到IIS
一.创建WebGL代码 在win7下,Unity3D中发布WebGL,然后部署到IIS,只要代码是对,关键是添加mime类型 二.为网站添加mime类型 .json text/json .unity3 ...
- liblensfun 在 mingw 上编译时遇到的奇怪问题
ffmpeg 2018.07.15 增加 lensfun 滤镜; 这个滤镜需要 liblensfun 库; Website: http://lensfun.sourceforge.net/ Sourc ...
- Linux命令行下编辑常用的快捷键
Linux命令行编辑快捷键: Ctrl+r 然后输入若干字符,开始向上搜索包含该字符的命令,继续按Ctrl+r,搜索上一条匹配的命令,按Ctrl+c或上下键退出. Ctrl+l 清屏 !num 执行命 ...
- liunx redis集群添加密码
第一种方法: 修改每个节点redis.conf配置文件: masterauth 123456 requirepass 123456 各个节点的密码都必须一致,否则Redirected就会失败 重新启动 ...
- vue-resource post请求后台接口报400(跨域问题解决方法)
1.打开config/index.js,在proxyTable中添写如下代码 proxyTable: { '/api': { //使用"/api"来代替"http://f ...
- 1、在Centos上安装Grafana
1.如果你想将老版本的Grafana升级为新版本的Grafana,可以阅读链接中的文档指南: http://docs.grafana.org/installation/upgrading/ 2.使用y ...
- Gradle: Download 下载慢的解决办法
应该是gradle被墙了,在网上查得:使用阿里云的国内镜像仓库地址,就可以快速的下载需要的文件: 修改项目根目录下的文件 build.gradle : buildscript { repositori ...
- javascript 通过模块模式实现代码访问控制
<script type="text/javascript"> // 在匿名函数中使用var关键字 (function(){ var privateField = 42 ...