openGauss学习笔记-28 openGauss 高级数据管理-NULL值
NULL值代表未知数据。无法比较NULL和0,因为它们是不等价的。
创建表时,可以指定列可以存放或者不能存放NULL值,详情请参见NOT NULL约束。本节介绍IS NULL和IS NOT NULL操作符。
创建表customer_t1,数据如下:
openGauss=# SELECT * FROM customer_t1;
c_customer_sk | c_customer_id | c_first_name | c_last_name | amount
---------------+---------------+--------------+-------------+--------
3869 | hello | Grace | | 1000
3869 | | Grace | |
3869 | hello | | |
6985 | maps | Joes | | 2200
9976 | world | James | | 5000
4421 | Admin | Local | | 3000
(6 rows)
28.1 IS NOT NULL
在WHERE子句中查找为NULL值的字段。
例如,列出表customer_t1中c_customer_id不为空值的字段。
openGauss=# SELECT * FROM customer_t1 WHERE c_customer_id IS NOT NULL;
c_customer_sk | c_customer_id | c_first_name | c_last_name | amount
---------------+---------------+--------------+-------------+--------
3869 | hello | Grace | | 1000
3869 | hello | | |
6985 | maps | Joes | | 2200
9976 | world | James | | 5000
4421 | Admin | Local | | 3000
(5 rows)
28.2 IS NULL
在WHERE子句中查找为NULL值的字段。
例如,列出表customer_t1中c_customer_id为空值的字段。
openGauss=# SELECT * FROM customer_t1 WHERE c_customer_id IS NULL;
c_customer_sk | c_customer_id | c_first_name | c_last_name | amount
---------------+---------------+--------------+-------------+--------
3869 | | Grace | |
(1 row)
标签:customer,3869,name,28,openGauss,NULL,id From: https://blog.51cto.com/u_237826/6941562