SQL'AND'或'OR'首先出现吗? [英] SQL 'AND' or 'OR' comes first?

查看:99
本文介绍了SQL'AND'或'OR'首先出现吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下查询:

SELECT * FROM MUFFIN_TYPES MT
  WHERE MT.flavor IS NULL 
    OR MT.flavor IS NOT NULL 
    AND MT.additionDate IS NOT NULL

如果不弄清楚括号,这是令人困惑的. MT.flavor IS NULL OR MT.flavor IS NOT NULL总是等于true吗?还是将其评估为MT.flavor IS NULL (OR MT.flavor IS NOT NULL AND MT.additionDate IS NOT NULL)?

Without clarifying parenthesis this is confusing. Would MT.flavor IS NULL OR MT.flavor IS NOT NULL always evaluate to true? Or would it evaluate as MT.flavor IS NULL (OR MT.flavor IS NOT NULL AND MT.additionDate IS NOT NULL)?

我找不到有关此事的任何文档.我是两个选项中的后者,但我不确定.

I couldn't find any documentation on the matter. I the latter of the two options, but I'm not sure.

注意:我正在使用Oracle Pl/SQL.

Note: I'm using Oracle Pl/SQL.

推荐答案

AND的优先级高于OR:

AND has higher precedence than OR:

来自 Oracle 12.1文档(优先级AND和OR至少与版本7一致-可能更进一步,但我没有文档链接)

From Oracle 12.1 docs (precedence for AND and OR is consistent to at least version 7 - probably further but I don't have documentation links)

以前的版本:

  • Version 8
  • Version 7

运算符优先级从最高到最高显示在以下列表中 优先级最低.在一行上同时显示的运算符 具有相同的优先级.

Operator precedences are shown in the following list, from highest precedence to the lowest. Operators that are shown together on a line have the same precedence.

INTERVAL
BINARY, COLLATE
!
- (unary minus), ~ (unary bit inversion)
^
*, /, DIV, %, MOD
-, +
<<, >>
&
|
= (comparison), <=>, >=, >, <=, <, <>, !=, IS, LIKE, REGEXP, IN
BETWEEN, CASE, WHEN, THEN, ELSE
NOT
&&, AND
XOR
||, OR
= (assignment), :=

但是,我极力鼓励使用括号以保持清楚并确保按您期望的顺序对运算符进行评估.

However I would HIGHLY encourage the use of parentheses both for clarity and to ENSURE that the operators are evaluated in the order that you intend.

这篇关于SQL'AND'或'OR'首先出现吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆