sql 判断为空不为空_SQL为空,SQL不为空

sql 判断为空不为空

Sometimes we have columns where null values are allowed. In such cases, SQL IS NULL is a very useful operator.

有时我们有允许空值的列。 在这种情况下,SQL IS NULL是一个非常有用的运算符

SQL IS NULL operator is used to checking if the value of a column is null or not. The operator filters the result set based on the null column value.

SQL IS NULL运算符用于检查列的值是否为null。 操作员根据空列值过滤结果集。

Let’s discuss in detail about the IS NULL operator.

让我们详细讨论IS NULL运算符。

SQL IS NULL (SQL IS NULL)

Let’s have a quick look at SQL is null operator syntax.

让我们快速了解一下SQL是null运算符语法。

SELECT Column(s) FROM table_name WHERE column IS NULL;

Above query will give us result set where specified column value is null.

上面的查询将为我们提供结果集,其中指定的列值为null。

We will understand the above-mentioned syntax in more detail through some examples.

通过一些示例,我们将更详细地理解上述语法。

Let’s consider the following Student table for example purpose.

让我们考虑以下学生表格作为示例。

RollNoStudentNameStudentGenderStudentAgeStudentPercent
1GeorgeM1485
2MonicaF1288
3JessicaFnull84
4TomMnull78
卷号 学生姓名 学生性别 学生年龄 学生百分比
1个 乔治 中号 14 85
2 莫妮卡 F 12 88
3 杰西卡(Jessica) F 空值 84
4 汤姆 中号 空值 78

Scenario: Get the percentage of students whose age is null.

方案 :获取年龄为零的学生的百分比。

SELECT StudentPercent FROM Student WHERE StudentAge IS NULL;

Output:

输出:

StudentPercent
88
78
学生百分比
88
78

Oracle空字符串等效于NULL (Oracle Empty String is equivalent to NULL)

Null is not just limited to the null keyword in Oracle database, in fact, the columns who have blank value also are considered as null when using IS NULL operator. Note that these columns types should be VARCHAR and not CHAR.

空值不仅限于Oracle数据库中的null关键字,实际上,使用IS NULL运算符时,具有空值的列也被视为空值。 请注意,这些列类型应为VARCHAR而不是CHAR。

We found similar behavior for PostgreSQL database but not in MySQL database. So this seems to be database specific behaviour.
对于PostgreSQL数据库,我们发现了类似的行为,但在MySQL数据库中却没有。 因此,这似乎是数据库特定的行为。

Let’s consider the following Supplier table for example purpose.

让我们考虑以下供应商表作为示例。

ProductIdProductNameSupplierName
1CookieABC
2Cheese
3Chocolate
4JamXDE
产品编号 产品名称 供应商名称
1个 曲奇饼 美国广播公司
2 起司
3 巧克力
4 果酱 XDE

Scenario: Get the name of the product where supplier name is not available.

场景 :获取没有供应商名称的产品名称。

SELECT ProductName FROM Supplier WHERE SupplierName IS NULL;

Output:

输出:

ProductName
Cheese
Chocolate
产品名称
起司
巧克力

SQL不为空 (SQL IS NOT NULL)

SQL IS NOT NULL operator is used to filter the result if the column that is used in WHERE clause contains non-null values.

如果WHERE子句中使用的列包含非null值,则使用SQL IS NOT NULL运算符过滤结果。

Let’s discuss in detail about IS NOT NULL operator.

让我们详细讨论一下IS NOT NULL运算符。

Syntax:

语法

SELECT Column(s) FROM table_name WHERE Column IS NOT NULL;

In the syntax above the column values that are not null will be filtered for the result.

在上面的语法中,将为结果过滤不为null的列值。

Let’s consider the earlier defined Supplier table for example purpose.

让我们以先前定义的Supplier表为例。

Scenario: Get the name of the product whose supplier name is not null.

场景 :获取供应商名称不为null的产品的名称。

SELECT ProductName FROM Supplier WHERE SupplierName IS NOT NULL;

Output:

输出

SupplierName
Cookie
Jam
供应商名称
曲奇饼
果酱

翻译自: https://www.journaldev.com/19897/sql-is-null-sql-is-not-null

sql 判断为空不为空

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值