1、NULL是什么
#include <stddef.h>#include <stdio.h>void main(){ if ('0' == NULL) printf("NULL is '0' \n"); if ("" == NULL) printf("NULL is empty string \n"); if (' ' == NULL) printf("NULL is space \n"); if (0 == NULL) printf("NULL is 0 \n");}
public class Test
{
public static void main (String[] args) throws java.lang.Exception
{
System.out.println("Null is: " + null);
}
}
Null is: null
postgres=# SELECT 1 = 1 result;
result
--------
t
(1 row)
postgres=# SELECT 'foo' = 'foo' result;
result
--------
t
(1 row)
postgres=# SELECT NULL = NULL result;
result
--------
(1 row)
postgres=# SELECT NULL != NULL result;
result
--------
(1 row)
postgres=# SELECT NULL * 10 is NULL result;
result
--------
t
(1 row)
2、如何使用NULL
postgres=# SELECT NULL is NULL result;
result
--------
t
(1 row)
postgres=# SELECT NULL is NOT NULL result;
result
--------
f
(1 row)
COALESCE (NULL, 2 , 1);
postgres=# SELECT NULLIF (10, 10);
nullif
--------
(1 row)
postgres=# SELECT NULLIF (10, 100);
nullif
--------
10
(1 row)
3、NULL的使用
postgres=# CREATE TABLE student(id INTEGER, fname TEXT, sname TEXT, lname TEXT, age INTEGER);
postgres=# SELECT * FROM STUDENT;
id | fname | sname | lname | age
----+-------+-------+-------+-----
1 | Adams | Baker | Clark | 21
2 | Davis | | Evans | 22
3 | Ghosh | Hills | | 24
(3 rows)
postgres=# SELECT * FROM STUDENT WHERE sname = '';
id | fname | sname | lname | age
----+-------+-------+-------+-----
(0 rows)
postgres=# SELECT * FROM STUDENT WHERE sname IS NULL;
id | fname | sname | lname | age
----+-------+-------+-------+-----
2 | Davis | | Evans | 22
(1 row)
postgres=# CREATE TABLE person(id INTEGER, name TEXT, type TEXT, divorced bool);
postgres=# SELECT * FROM person;
id | name | type | divorced
----+-------+-------+---------
1 | Alice | WOMAN | f
3 | Davis | KID |
2 | Bob | MAN | t
(3 rows)
postgres=# SELECT * FROM students_mark;
id | name | marks
----+-------+-------
1 | Alex | 90
2 | Bob | 0
2 | Davis |
(3 rows)
postgres=# SELECT * FROM students_mark WHERE marks IS NULL;
id | name | marks
----+-------+-------
2 | Davis |
(1 row)
postgres=# SELECT * FROM students_mark WHERE marks = 0;
id | name | marks
----+------+-------
2 | Bob | 0
(1 row)
参考
最后修改时间:2022-12-03 20:00:45
文章转载自yanzongshuaiDBA,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。