Sqlite-operators

提供:Dev Guides
移動先:案内検索

SQLite-演算子

SQLiteのオペレーターとは何ですか?

演算子は、比較や算術演算などの操作を実行するためにSQLiteステートメントのWHERE句で主に使用される予約語または文字です。

演算子は、SQLiteステートメントで条件を指定し、ステートメント内の複数の条件の組み合わせとして機能するために使用されます。

  • 算術演算子
  • 比較演算子
  • 論理演算子
  • ビットごとの演算子

SQLiteの算術演算子

変数 a が10を保持し、変数 b が20を保持すると仮定すると、SQLite算術演算子は次のように使用されます-

リンク:/sqlite/sqlite_arithmetic_operators [例を表示]

Operator Description Example
+ (Addition) Adds values on either side of the operator a + b will give 30
- (Subtraction) Subtracts the right hand operand from the left hand operand a - b will give -10
*(Multiplication) Multiplies values on either side of the operator a* b will give 200
/(Division) Divides the left hand operand by the right hand operand b/a will give 2
% (Modulus) Divides the left hand operand by the right hand operand and returns the remainder b % a will give 0

SQLite比較演算子

変数 a が10を保持し、変数 b が20を保持すると仮定すると、SQLite比較演算子は次のように使用されます

リンク:/sqlite/sqlite_comparison_operators [例を表示]

Operator Description Example
== Checks if the values of two operands are equal or not, if yes then the condition becomes true. (a == b) is not true.
= Checks if the values of two operands are equal or not, if yes then the condition becomes true. (a = b) is not true.
!= Checks if the values of two operands are equal or not, if the values are not equal, then the condition becomes true. (a != b) is true.
<> Checks if the values of two operands are equal or not, if the values are not equal, then the condition becomes true. (a <> b) is true.
> Checks if the values of the left operand is greater than the value of the right operand, if yes then the condition becomes true. (a > b) is not true.
< Checks if the values of the left operand is less than the value of the right operand, if yes then the condition becomes true. (a < b) is true.
>= Checks if the value of the left operand is greater than or equal to the value of the right operand, if yes then the condition becomes true. (a >= b) is not true.
Checks if the value of the left operand is less than or equal to the value of the right operand, if yes then the condition becomes true. (a ⇐ b) is true.
!< Checks if the value of the left operand is not less than the value of the right operand, if yes then the condition becomes true. (a !< b) is false.
!> Checks if the value of the left operand is not greater than the value of the right operand, if yes then the condition becomes true. (a !> b) is true.

SQLite論理演算子

以下は、SQLiteで使用可能なすべての論理演算子のリストです。

リンク:/sqlite/sqlite_logical_operators [例を表示]

シニア

演算子と説明

1

そして

AND演算子を使用すると、SQLステートメントのWHERE句に複数の条件を含めることができます。

2

の間に

BETWEEN演算子は、最小値と最大値を指定して、値のセット内にある値を検索するために使用されます。

3

存在

EXISTS演算子は、特定の基準を満たす特定のテーブル内の行の存在を検索するために使用されます。

4

IN

IN演算子は、値を指定されたリテラル値のリストと比較するために使用されます。

5

ありませんで

値を指定されたリテラル値のリストと比較するために使用されるIN演算子の否定。

6

好き

LIKE演算子は、ワイルドカード演算子を使用して値を同様の値と比較するために使用されます。

7

*GLOB*

GLOB演算子は、ワイルドカード演算子を使用して値を同様の値と比較するために使用されます。 また、LIKEとは異なり、GLOBでは大文字と小文字が区別されます。

8

*NOT*

NOT演算子は、使用される論理演算子の意味を逆にします。 Eg. 存在しない、間にない、ない、など これは否定演算子です。

9

OR

OR演算子は、SQLステートメントのWHERE句で複数の条件を結合するために使用されます。

10

無効です

NULL演算子は、値をNULL値と比較するために使用されます。

11

IS

IS演算子は=のように動作します

12

ではない

IS演算子は!=のように機能します

13

||

2つの異なる文字列を追加して、新しい文字列を作成します。

14

ユニーク

UNIQUE演算子は、指定されたテーブルのすべての行の一意性(重複なし)を検索します。

SQLiteビット演算子

ビット演算子はビットに対して機能し、ビットごとの操作を実行します。 以下は、&*および *| の真理値表です。

p q p & q p
q 0 0 0
0 0 1 0
1 1 1 1
1 1 0 0
*A* = 60であると仮定します。および *B* = 13、その後バイナリ形式で、それらは次のようになります-

A = 0011 1100

B = 0000 1101

A&B = 0000 1100

A | B = 0011 1101

〜A = 1100 0011

SQLite言語でサポートされているビット単位の演算子を次の表にリストします。 変数 *A* が60を保持し、変数 *B* が13を保持すると仮定します-

リンク:/sqlite/sqlite_bitwise_operators [例を表示]

[cols=",,",options="header",]
|===
|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
|===