📅  最后修改于: 2020-11-12 09:37:34             🧑  作者: Mango
当我们使用WHERE子句执行比较和算术运算之类的操作时,SQLite运算符是SQLite语句中使用的保留字或字符。
运算符可用于指定条件,并可作为SQLite语句中多个条件的结合。
SQLite中主要有四种类型的运算符:
下表指定了SQLite中的不同算术运算运算符。在此表中,我们有两个变量“ a”和“ b”分别保持值50和100。
Operator | Description | Example |
---|---|---|
+ | Addition Operator: It is used to add the values of both side of the operator. | a+b = 150 |
– | Subtraction Operator: It is used to subtract the right hand operand from left hand operand. | a-b = -50 |
* | Multiplication Operator: It is used to multiply the values of both sides. | a*b = 5000 |
/ | Division Operator: It is used to divide left hand operand by right hand operand. | a/b = 0.5 |
% | Modulus Operator: It is used to divide left hand operand by right hand operand and returns remainder. | b/a = 0 |
下表指定SQLite中不同的运算符。在此表中,我们有两个变量“ a”和“ b”分别保持值50和100。
Operator | Description | Example |
---|---|---|
== | It is used to check if the values of two operands are equal or not, if yes then condition becomes true. | (a == b) is not true. |
= | It is used to check if the values of two operands are equal or not, if yes then condition becomes true. | (a = b) is not true. |
!= | It is used to check if the values of two operands are equal or not, if values are not equal then condition becomes true. | (a != b) is true. |
<> | It is used to check if the values of two operands are equal or not, if values are not equal then condition becomes true. | (a <> b) is true. |
> | It is used to check if the values of left operand is greater than the value of right operand, if yes then condition becomes true. | (a > b) is not true. |
< | It is used to check if the values of left operand is less than the value of right operand, if yes then condition becomes true. | (a < b) is true. |
>= | It is used to check if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. | (a >= b) is not true. |
<= | It is used to check if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. | (a <= b) is true. |
!< | It is used to check if the value of left operand is not less than the value of right operand, if yes then condition becomes true. | (a !< b) is false. |
!> | It is used to check if the value of left operand is not greater than the value of right operand, if yes then condition becomes true. | (a !> b) is true. |
以下是SQLite中的逻辑运算符的列表:
Operator | Description |
---|---|
AND | The AND operator allows the existence of multiple conditions in an SQL statement’s WHERE clause. |
BETWEEN | The BETWEEN operator is used to search for values that are within a set of values, given the minimum value and the maximum value. |
EXISTS | The EXISTS operator is used to search for the presence of a row in a specified table that meets certain criteria. |
IN | The IN operator is used to compare a value to a list of literal values that have been specified. |
NOT IN | It is the negation of IN operator which is used to compare a value to a list of literal values that have been specified. |
LIKE | The LIKE operator is used to compare a value to similar values using wildcard operators. |
GLOB | The GLOB operator is used to compare a value to similar values using wildcard operators. Also, glob is case sensitive, unlike like. |
NOT | The NOT operator reverses the meaning of the logical operator with which it is used. For example: EXISTS, NOT BETWEEN, NOT IN, etc. These are known as negate operator. |
OR | The OR operator is used to combine multiple conditions in an SQL statement’s where clause. |
IS NULL | The NULL operator is used to compare a value with a null value. |
IS | The IS operator work like = |
IS NOT | The IS NOT operator work like != |
|| | This operator is used to add two different strings and make new one. |
UNIQUE | The UNIQUE operator searches every row of a specified table for uniqueness (no duplicates). |
SQLite按位运算符对位进行处理,并逐位执行操作。
请参阅二进制AND(&)和Binary OR(|)的真值表:
p | q | p&q | p|q |
---|---|---|---|
0 | 0 | 0 | 0 |
0 | 1 | 0 | 1 |
1 | 1 | 1 | 1 |
1 | 0 | 0 | 1 |
假设两个变量“ a”和“ b”分别具有值60和13。因此a和b的二进制值为:
a = 0011 1100
b = 0000 1101
a&b = 0000 1100
a | b = 0011 1101
〜a = 1100 0011
Operator | Description | Example |
---|---|---|
& | Binary AND operator copies a bit to the result if it exists in both operands. | (a & b) will give 12 which is 0000 1100 |
| | Binary OR Operator copies a bit if it exists in either operand. | (a | b) will give 61 which is 0011 1101 |
~ | Binary Ones Complement Operator is unary and has the effect of ‘flipping’ bits. | (~a ) will give -61 which is 1100 0011 in 2’s complement form due to a signed binary number. |
<< | Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand. | a << 2 will give 240 which is 1111 0000 |
>> | Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand. | a >> 2 will give 15 which is 0000 1111 |