Oracle数据库的比较运算符Comparison Operators

Comparison operators compare one expression to another. The result is always either TRUE, FALSE, or NULL.

If the value of one expression is NULL, then the result of the comparison is also NULL.
如果一个表达式的值为NULL,那么比较的结果也是NULL。

The comparison operators are:

  • IS [NOT] NULL Operator
  • Relational Operators
  • LIKE Operator
  • BETWEEN Operator
  • IN Operator
CREATE OR REPLACE PROCEDURE print_boolean (b_name   VARCHAR2,b_value  BOOLEAN
) AUTHID DEFINER IS
BEGINIF b_value IS NULL THENDBMS_OUTPUT.PUT_LINE (b_name || ' = NULL');ELSIF b_value = TRUE THENDBMS_OUTPUT.PUT_LINE (b_name || ' = TRUE');ELSEDBMS_OUTPUT.PUT_LINE (b_name || ' = FALSE');END IF;
END;
/

1. IS [NOT] NULL Operator

The IS NULL operator returns the BOOLEAN value TRUE if its operand is NULL or FALSE if it is not NULL. The IS NOT NULL operator does the opposite.

Comparisons involving NULL values always yield NULL.

To test whether a value is NULL, use IF value IS NULL, as in these examples:

1.1 Variable Initialized to NULL by Default

In this example, the variable counter has the initial value NULL, by default. The example uses the “IS [NOT] NULL Operator” to show that NULL is different from zero.

DECLAREcounter INTEGER;  -- initial value is NULL by default
BEGINcounter := counter + 1;  -- NULL + 1 is still NULLIF counter IS NULL THENDBMS_OUTPUT.PUT_LINE('counter is NULL.');END IF;
END;
/
-- run result 
counter is NULL. 

1.2 Procedure Prints BOOLEAN Variable"

DECLAREPROCEDURE print_x_and_y (x  BOOLEAN,y  BOOLEAN) ISBEGINprint_boolean ('x', x);print_boolean ('y', y);print_boolean ('x AND y', x AND y);END print_x_and_y;BEGINprint_x_and_y (FALSE, FALSE);print_x_and_y (TRUE, FALSE);print_x_and_y (FALSE, TRUE);print_x_and_y (TRUE, TRUE);print_x_and_y (TRUE, NULL);print_x_and_y (FALSE, NULL);print_x_and_y (NULL, TRUE);print_x_and_y (NULL, FALSE);
END;
/
-- run result 
x = FALSE
y = FALSE
x AND y = FALSE
x = TRUE
y = FALSE
x AND y = FALSE
x = FALSE
y = TRUE
x AND y = FALSE
x = TRUE
y = TRUE
x AND y = TRUE
x = TRUE
y = NULL
x AND y = NULL
x = FALSE
y = NULL
x AND y = FALSE
x = NULL
y = TRUE
x AND y = NULL
x = NULL
y = FALSE
x AND y = FALSE

1.3 Searched CASE Expression with WHEN … IS NULL

DECLAREgrade CHAR(1); -- NULL by defaultappraisal VARCHAR2(20);
BEGINappraisal :=CASEWHEN grade IS NULL THEN 'No grade assigned'WHEN grade = 'A' THEN 'Excellent'WHEN grade = 'B' THEN 'Very Good'WHEN grade = 'C' THEN 'Good'WHEN grade = 'D' THEN 'Fair'WHEN grade = 'F' THEN 'Poor'ELSE 'No such grade'END;DBMS_OUTPUT.PUT_LINE ('Grade ' || grade || ' is ' || appraisal);
END;
/
-- run result
Grade  is No grade assigned 

2. Relational Operators

Operator Meaning

OperatorOperator
=equal to
<>, !=, ~=, ^=not equal to
<less than
>greater than
<=less than or equal to
>=greater than or equal to

Topics

  • Arithmetic Comparisons
  • BOOLEAN Comparisons
  • Character Comparisons
  • Date Comparisons

2.1 Relational Operators in Expressions

This example invokes the print_boolean procedure print the values of expressions that use relational operators to compare arithmetic values.

BEGINprint_boolean ('(2 + 2 =  4)', 2 + 2 = 4);print_boolean ('(2 + 2 <> 4)', 2 + 2 <> 4);print_boolean ('(2 + 2 != 4)', 2 + 2 != 4);print_boolean ('(2 + 2 ~= 4)', 2 + 2 ~= 4);print_boolean ('(2 + 2 ^= 4)', 2 + 2  ^= 4);print_boolean ('(1 < 2)', 1 < 2);print_boolean ('(1 > 2)', 1 > 2);print_boolean ('(1 <= 2)', 1 <= 2);print_boolean ('(1 >= 1)', 1 >= 1);
END;
/
-- run result
BEGINprint_boolean ('(2 + 2 =  4)', 2 + 2 = 4);print_boolean ('(2 + 2 <> 4)', 2 + 2 <> 4);print_boolean ('(2 + 2 != 4)', 2 + 2 != 4);print_boolean ('(2 + 2 ~= 4)', 2 + 2 ~= 4);print_boolean ('(2 + 2 ^= 4)', 2 + 2  ^= 4);print_boolean ('(1 < 2)', 1 < 2);print_boolean ('(1 > 2)', 1 > 2);print_boolean ('(1 <= 2)', 1 <= 2);print_boolean ('(1 >= 1)', 1 >= 1);
END;
/

2.2 BOOLEAN Comparisons

By definition, TRUE is greater than FALSE. Any comparison with NULL returns NULL.

2.3 Character Comparisons

By default, one character is greater than another if its binary value is larger.

For example, this expression is true:

'y' > 'r'

Strings are compared character by character. For example, this expression is true:

'Kathy' > 'Kathryn'

2.4 Date Comparisons

One date is greater than another if it is more recent.

For example, this expression is true:

'01-JAN-91' > '31-DEC-90'

3. LIKE Operator

LIKE Operator
The LIKE operator compares a character, string, or CLOB value to a pattern and returns TRUE if the value matches the pattern and FALSE if it does not.

Case is significant.

The pattern can include the two wildcard characters underscore (_) and percent sign (%).

Underscore matches exactly one character.

Percent sign (%) matches zero or more characters.

To search for the percent sign or underscore, define an escape character and put it before the percent sign or underscore.

3.1 LIKE Operator in Expression

The string ‘Johnson’ matches the pattern ‘J%s_n’ but not ‘J%S_N’, as this example shows.

DECLAREPROCEDURE compare (value   VARCHAR2,pattern VARCHAR2) ISBEGINIF value LIKE pattern THENDBMS_OUTPUT.PUT_LINE ('TRUE');ELSEDBMS_OUTPUT.PUT_LINE ('FALSE');END IF;END;
BEGINcompare('Johnson', 'J%s_n');compare('Johnson', 'J%S_N');
END;
/
-- run result
TRUE
FALSE 

4. BETWEEN Operator

The BETWEEN operator tests whether a value lies in a specified range.

The value of the expression x BETWEEN a AND b is defined to be the same as the value of the expression (x>=a) AND (x<=b) . The expression x will only be evaluated once.

4.1 BETWEEN Operator in Expressions

This example invokes the print_boolean procedure print the values of expressions that include the BETWEEN operator.

BEGINprint_boolean ('2 BETWEEN 1 AND 3', 2 BETWEEN 1 AND 3);print_boolean ('2 BETWEEN 2 AND 3', 2 BETWEEN 2 AND 3);print_boolean ('2 BETWEEN 1 AND 2', 2 BETWEEN 1 AND 2);print_boolean ('2 BETWEEN 3 AND 4', 2 BETWEEN 3 AND 4);
END;
/
-- run result
2 BETWEEN 1 AND 3 = TRUE
2 BETWEEN 2 AND 3 = TRUE
2 BETWEEN 1 AND 2 = TRUE
2 BETWEEN 3 AND 4 = FALSEPL/SQL procedure successfully completed.

5. IN Operator

The IN operator tests set membership.

x IN (set) returns TRUE only if x equals a member of set.

5.1 IN Operator in Expressions

This example invokes the print_boolean procedure print the values of expressions that include the IN operator.

DECLAREletter VARCHAR2(1) := 'm';
BEGINprint_boolean ('letter IN (''a'', ''b'', ''c'')',letter IN ('a', 'b', 'c'));print_boolean ('letter IN (''z'', ''m'', ''y'', ''p'')',letter IN ('z', 'm', 'y', 'p'));
END;
/
-- run result
letter IN ('a', 'b', 'c') = FALSE
letter IN ('z', 'm', 'y', 'p') = TRUEPL/SQL procedure successfully completed.

5.2 IN Operator with Sets with NULL Values

This example shows what happens when set includes a NULL value. This invokes the print_boolean procedure

DECLAREa INTEGER; -- Initialized to NULL by defaultb INTEGER := 10;c INTEGER := 100;
BEGINprint_boolean ('100 IN (a, b, c)', 100 IN (a, b, c));print_boolean ('100 NOT IN (a, b, c)', 100 NOT IN (a, b, c));print_boolean ('100 IN (a, b)', 100 IN (a, b));print_boolean ('100 NOT IN (a, b)', 100 NOT IN (a, b));print_boolean ('a IN (a, b)', a IN (a, b));print_boolean ('a NOT IN (a, b)', a NOT IN (a, b));
END;
/
-- run result
100 IN (a, b, c) = TRUE
100 NOT IN (a, b, c) = FALSE
100 IN (a, b) = NULL
100 NOT IN (a, b) = NULL
a IN (a, b) = NULL
a NOT IN (a, b) = NULLPL/SQL procedure successfully completed. 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/880173.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

5、论文阅读:深水下的图像增强

深水下的图像增强 前言介绍贡献UWCNN介绍网络架构残差Residuals块 Blocks网络层密集串联网络深度减少边界伪影网络损失Loss后处理前言 水下场景中,与波长相关的光吸收和散射会降低图像的可见度,导致对比度低和色偏失真。为了解决这个问题,我们提出了一种基于卷积神经网络的…

伊犁云计算22-1 apache 安装rhel8

1 局域网网络必须通 2 yum 必须搭建成功 3 apache 必须安装 开干 要用su 用户来访问 一看httpd 组件安装完毕 到这里就是测试成功了 如何修改主页的目录 网站目录默认保存在/var/WWW/HTML 我希望改变/home/www 122 127 167 行要改

打造灵活DateTimePicker日期时间选择器组件:轻松实现时间的独立清除功能

element ui中日期和时间选择器&#xff08;DateTimePicker&#xff09;是一个常见且重要的组件。它允许用户轻松地选择日期和时间&#xff0c;极大地提升了用户体验。然而&#xff0c;在某些场景下&#xff0c;用户可能需要更细粒度的控制&#xff0c;例如单独清除已选择的时间…

Swagger 概念和使用以及遇到的问题

前言 接口文档对于前后端开发人员都十分重要。尤其近几年流行前后端分离后接口文档又变 成重中之重。接口文档固然重要,但是由于项目周期等原因后端人员经常出现无法及时更新&#xff0c; 导致前端人员抱怨接口文档和实际情况不一致。 很多人员会抱怨别人写的接口文档不…

Cassandra 5.0 Spring Boot 3.3 CRUD

概览 因AI要使用到向量存储&#xff0c;JanusGraph也使用到Cassandra 卸载先前版本 docker stop cassandra && docker remove cassandra && rm -rf cassandra/运行Cassandra容器 docker run \--name cassandra \--hostname cassandra \-p 9042:9042 \--pri…

【HarmonyOS】深入理解@Observed装饰器和@ObjectLink装饰器:嵌套类对象属性变化

【HarmonyOS】深入理解Observed装饰器和ObjectLink装饰器&#xff1a;嵌套类对象属性变化 前言 之前就Observed和ObjectLink写过一篇讲解博客【HarmonyOS】 多层嵌套对象通过ObjectLink和Observed实现渲染更新处理&#xff01; 其中就Observe监听类的使用&#xff0c;Object…

ZXing.Net:一个开源条码生成和识别器,支持二维码、条形码等

推荐一个跨平台的非常流行的条码库&#xff0c;方便我们在.Net项目集成条码扫描和生成功能。 01 项目简介 ZXing.Net是ZXing的.Net版本的开源库。支持跨多个平台工作&#xff0c;包括 Windows、Linux 和 macOS&#xff0c;以及在 .NET Core 和 .NET Framework 上运行。 解码…

硬件看门狗导致MCU启动时间慢

最近&#xff0c;在项目交付过程中&#xff0c;我们遇到了一个有趣的问题&#xff0c;与大家分享一下。 客户的需求是&#xff1a;在KL15电压上电后&#xff0c;MCU需要在200ms内发送出第一包CAN报文数据。然而&#xff0c;实际测试结果显示&#xff0c;软件需要360ms才能发送…

【通俗易懂介绍OAuth2.0协议以及4种授权模式】

文章目录 一.OAuth2.0协议介绍二.设计来源于生活三.关于令牌与密码的区别四.应用场景五.接下来分别简单介绍下四种授权模式吧1.客户端模式1.1 介绍1.2 适用场景1.3 时序图 2.密码模式2.1 介绍2.2 适用场景2.3时序图 3.授权码模式3.1 介绍3.2 适用场景3.3 时序图 4.简化模式4.1 …

MES系统如何提升制造企业的运营效率和灵活性

参考拓展&#xff1a;苏州稳联-西门子MES系统-赋能智能制造的核心引擎 制造执行系统(MES)在提升制造企业运营效率和灵活性方面发挥着关键作用。 一、MES系统的基本概念和功能 MES系统是连接企业管理层与生产现场的重要桥梁。它主要负责生产调度、资源管理、质量控制等多个方…

安全热点问题

安全热点问题 1.DDOS2.补丁管理3.堡垒机管理4.加密机管理 1.DDOS 分布式拒绝服务攻击&#xff0c;是指黑客通过控制由多个肉鸡或服务器组成的僵尸网络&#xff0c;向目标发送大量看似合法的请求&#xff0c;从而占用大量网络资源使网络瘫痪&#xff0c;阻止用户对网络资源的正…

TMStarget学习——T1 Segmentation数据处理及解bug

最新学习季公俊老师的神器 TMStarget 的第一个模块基于结构像的靶区计算T1 segmentation。下面上步骤&#xff1a; (1)在github 上下载 TMStarget https://github.com/jigongjun/Neuroimaging-and-Neuromodulation (2)按照要求下载依赖工具软件AFQ、vistasoft、SPM12 &#…

OpenAI o1团队突破性论文:『过程推理』中数学推理能力大幅提升,从正确中学习的新方法

原创 超 近年来&#xff0c;大型语言模型(LLMs)在复杂的多步推理任务中取得了令人瞩目的进展。这些模型能够生成逐步的思维链&#xff0c;解决从小学数学到高等微积分的各种问题。然而&#xff0c;即使是最先进的模型也常常陷入逻辑陷阱&#xff0c;产生看似合理但实际错误的推…

1.3 计算机网络的分类

欢迎大家订阅【计算机网络】学习专栏&#xff0c;开启你的计算机网络学习之旅&#xff01; 文章目录 前言一、按分布范围分类二、按传输技术分类三、按拓扑结构分类四、按使用者分类五、按传输介质分类 前言 计算机网络根据不同的标准可以被分为多种类型&#xff0c;本章从分布…

QT----基于QML的计时器

赶上了实习的末班车,现在在做QML开发,第一天的学习成果,一个计时器.逻辑挺简单的,纯QML实现,代码在仓库QT-Timer 学习使用c的listmodel 学习使用了如何用c的listmodel来存储数据. 新建一个TImeListModel类继承自QAbstractListModel class TimeListModel : public QAbstrac…

STM32CUBEIDE FreeRTOS操作教程(五):mutex互斥信号量

STM32CUBEIDE FreeRTOS操作教程&#xff08;五&#xff09;&#xff1a;mutex互斥信号量 STM32CUBE开发环境集成了STM32 HAL库进行FreeRTOS配置和开发的组件&#xff0c;不需要用户自己进行FreeRTOS的移植。这里介绍最简化的用户操作类应用教程。以STM32F401RCT6开发板为例&am…

蓝牙技术|详谈蓝牙信道探测技术,可实现厘米级精准定位

2024年9月5日&#xff0c;蓝牙技术联盟发布蓝牙6.0核心规范。相比此前各版本&#xff0c;蓝牙核心规范6.0版的主要创新和新功能包括&#xff1a;支持蓝牙信道探测、同步适配层增强、LL扩展功能和 帧空间更新。 蓝牙信道探测 市场上已经有不少高精度定位技术了&#xff0c;像 …

ToF传感器更新

我们最近改进了 ToF 解码管道&#xff08;固件&#xff09;和 ToF 工厂校准&#xff0c;该校准已应用于我们最新的带有 ToF 相机的OAK-D-SR-PoE 1. 点云 这是直接来自摄像机的原始点云&#xff08;没有应用任何后处理过滤器&#xff09;。 2. ToF 精度 &#xff08;ToF 深度误差…

界面控件Telerik UI for WinForms 2024 Q3概览 - 支持合并单元格等

Telerik UI for WinForms拥有适用Windows Forms的110多个令人惊叹的UI控件。所有的UI for WinForms控件都具有完整的主题支持&#xff0c;可以轻松地帮助开发人员在桌面和平板电脑应用程序提供一致美观的下一代用户体验。 本文将介绍界面组件Telerik UI for WinForms在今年第一…

3d可视化图片:通过原图和深度图实现

1、depthy 在线体验demo: https://depthy.stamina.pl/#/ 也可以docker安装上面服务: docker run --rm -t -i -p 9000:9000 ndahlquist/depthy http://localhost:90001)首先传原图 2)再传对应深度图 3)效果 </ifra