sql 判断为空不为空

您所在的位置:网站首页 sql不为空查询 sql 判断为空不为空

sql 判断为空不为空

2024-07-17 06:01:42| 来源: 网络整理| 查看: 265

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.

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

RollNoStudentNameStudentGenderStudentAgeStudentPercent1GeorgeM14852MonicaF12883JessicaFnull844TomMnull78 卷号 学生姓名 学生性别 学生年龄 学生百分比 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:

输出:

StudentPercent8878 学生百分比 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.

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

ProductIdProductNameSupplierName1CookieABC2Cheese3Chocolate4JamXDE 产品编号 产品名称 供应商名称 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:

输出:

ProductNameCheeseChocolate 产品名称 起司 巧克力 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:

输出 :

SupplierNameCookieJam 供应商名称 曲奇饼 果酱

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

sql 判断为空不为空



【本文地址】

公司简介

联系我们

今日新闻


点击排行

实验室常用的仪器、试剂和
说到实验室常用到的东西,主要就分为仪器、试剂和耗
不用再找了,全球10大实验
01、赛默飞世尔科技(热电)Thermo Fisher Scientif
三代水柜的量产巅峰T-72坦
作者:寞寒最近,西边闹腾挺大,本来小寞以为忙完这
通风柜跟实验室通风系统有
说到通风柜跟实验室通风,不少人都纠结二者到底是不
集消毒杀菌、烘干收纳为一
厨房是家里细菌较多的地方,潮湿的环境、没有完全密
实验室设备之全钢实验台如
全钢实验台是实验室家具中较为重要的家具之一,很多

推荐新闻


图片新闻

实验室药品柜的特性有哪些
实验室药品柜是实验室家具的重要组成部分之一,主要
小学科学实验中有哪些教学
计算机 计算器 一般 打孔器 打气筒 仪器车 显微镜
实验室各种仪器原理动图讲
1.紫外分光光谱UV分析原理:吸收紫外光能量,引起分
高中化学常见仪器及实验装
1、可加热仪器:2、计量仪器:(1)仪器A的名称:量
微生物操作主要设备和器具
今天盘点一下微生物操作主要设备和器具,别嫌我啰嗦
浅谈通风柜使用基本常识
 众所周知,通风柜功能中最主要的就是排气功能。在

专题文章

    CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭