null <> null
时间: 2024-04-16 09:20:21 浏览: 20
在SQL中,NULL表示未知或不适用的值,因此无法与任何值进行比较,包括NULL本身。因此,NULL <> NULL的结果是未知或不确定的,也就是说,它既不是真也不是假。如果要比较NULL值,应该使用IS NULL或IS NOT NULL语句。
示例代码如下:
```sql
SELECT * FROM table_name WHERE column_name IS NULL;
SELECT * FROM table_name WHERE column_name IS NOT NULL;
```
相关问题
select case when null = null then 1 null <> null then 2 else 3 end result_value from dual;
执行这个 SQL 语句的结果是 3。这是因为在 SQL 中,NULL 值与任何值都不相等,包括 NULL 本身。因此,当执行 `null = null` 时,结果为未知(unknown),而不是 true 或 false,因此会跳过第一个 `when` 子句,执行第二个 `when` 子句。同样,当执行 `null <> null` 时,结果也是未知(unknown),因此会执行 `else` 子句,返回结果值 3。在 SQL 中,判断 NULL 值是否相等或不相等时,应该使用 `is null` 或 `is not null` 来判断,而不是使用 `=` 或 `<>` 运算符。
select case when null = null then 1 when null < > null then 2 else 3 end result_value from dual;
The result of this query would be 1.
Explanation:
- The first condition "null = null" is evaluated as true.
- The second condition "null < > null" is evaluated as null, because any comparison with null results in null.
- Since the second condition is not true, the query moves on to the "else" clause and returns 3.
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)