简体   繁体   English

IBM DB2的运算符优先级

[英]Operator precedence for IBM DB2

What are the operator precedence rules for the DB2 RDBMS engine? DB2 RDBMS引擎的运算符优先级规则是什么?

I am looking for explicit rules which mention actual operators instead of precedence relations between groups of operators. 我正在寻找明确的规则来提及实际的运算符,而不是运算符组之间的优先级关系。

I found this document http://www-01.ibm.com/support/knowledgecenter/SSEPEK_10.0.0/com.ibm.db2z10.doc.sqlref/src/tpc/db2z_precedenceofoperations.dita via googling, but I am looking for something that goes into more detail, eg precedence relations between AND, OR and NOT 我通过谷歌搜索找到了该文档http://www-01.ibm.com/support/knowledgecenter/SSEPEK_10.0.0/com.ibm.db2z10.doc.sqlref/src/tpc/db2z_precedenceofoperations.dita ,但是我正在寻找一些东西详细介绍,例如AND,OR和NOT之间的优先级关系

If you're looking for search-condition operators, then see the Information Center section on Search conditions . 如果要查找搜索条件运算符,请参阅“ 搜索条件”中的“信息中心”部分。 Additional details are in the topic, but the basic rules are: 其他详细信息在主题中,但是基本规则是:

Search conditions within parentheses are evaluated first. 首先评估括号内的搜索条件。 If the order of evaluation is not specified by parentheses, NOT is applied before AND, and AND is applied before OR. 如果未通过括号指定评估顺序,则在AND之前应用NOT,在OR之前应用AND。 The order in which operators at the same precedence level are evaluated is undefined to allow for optimization of search conditions. 未定义优先级相同的运算符的评估顺序,以优化搜索条件。

From DB2 for z/OS 10.0.0>DB2 reference information>DB2 SQL>Language elements>Expressions>Precedence of operations DB2 for z / OS 10.0.0> DB2参考信息> DB2 SQL>语言元素>表达式>操作优先级

Expressions within parentheses are evaluated first. 首先评估括号内的表达式。 When the order of evaluation is not specified by parentheses, prefix operators are applied before multiplication and division, and multiplication, division, and concatenation are applied before addition and subtraction. 如果括号中未指定评估顺序,则在乘法和除法之前应用前缀运算符,并在加法和减法之前应用乘法,除法和级联。 Operators at the same precedence level are applied from left to right. 优先级相同的运算符从左到右应用。

I used a case in my order by and it seemed to work 我按顺序使用了一个案例,它似乎有效

 SELECT * FROM TABLE WHERE KEY IN (KEY1 , KEY2) ORDER BY CASE WHEN KEY = KEY1 THEN 1 ELSE 2 END 

I haven't check with more than 2 keys. 我没有检查超过2个键。

It's over here . 这里 Simple google could help you. 简单的谷歌可以帮助您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM