Plsql-operators
PL/SQL-演算子
この章では、PL/SQLの演算子について説明します。 演算子は、特定の数学的または論理的な操作を実行するようコンパイラーに指示する記号です。 PL/SQL言語は、組み込み演算子が豊富であり、次の種類の演算子を提供します-
- 算術演算子
- 関係演算子
- 比較演算子
- 論理演算子
- 文字列演算子
ここでは、算術演算子、関係演算子、比較演算子、論理演算子を1つずつ理解します。 文字列演算子については、後の章-* PL/SQL-文字列*で説明します。
算術演算子
次の表に、PL/SQLでサポートされているすべての算術演算子を示します。 *変数A *が10を保持し、*変数B *が5を保持すると仮定します-
リンク:/plsql/plsql_arithmetic_operators [例を表示]
Operator | Description | Example |
---|---|---|
+ | Adds two operands | A + B will give 15 |
- | Subtracts second operand from the first | A - B will give 5 |
* | Multiplies both operands | A* B will give 50 |
/ | Divides numerator by de-numerator | A/B will give 2 |
* * | Exponentiation operator, raises one operand to the power of other | A* *B will give 100000 |
関係演算子
関係演算子は、2つの式または値を比較し、ブール結果を返します。 次の表に、PL/SQLでサポートされるすべての関係演算子を示します。* 変数A *が10を保持し、*変数B *が20を保持すると仮定します-
リンク:/plsql/plsql_relational_operators [例を表示]
オペレーター
説明
例
=
2つのオペランドの値が等しいかどうかを確認し、等しい場合は条件が真になります。
(A = B)は正しくありません。
!=
<>
~=
2つのオペランドの値が等しいかどうかをチェックし、値が等しくない場合は条件が真になります。
(A!= B)は真です。
>
左のオペランドの値が右のオペランドの値よりも大きいかどうかをチェックし、そうであれば条件が真になります。
(A> B)は正しくありません。
<
左のオペランドの値が右のオペランドの値よりも小さいかどうかを確認し、そうであれば条件が真になります。
(A <B)は真です。
>=
左のオペランドの値が右のオペランドの値以上かどうかをチェックし、はいの場合は条件が真になります。
(A> = B)は正しくありません。
⇐
左のオペランドの値が右のオペランドの値以下かどうかをチェックし、そうであれば条件が真になります。
(A ⇐ B)はtrue
比較演算子
比較演算子は、ある式を別の式と比較するために使用されます。 結果は常に TRUE、FALSE または NULL のいずれかです。
リンク:/plsql/plsql_comparison_operators [例を表示]
Operator | Description | Example |
---|---|---|
LIKE | 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. | If 'Zara Ali' like 'Z% A_i' returns a Boolean true, whereas, 'Nuha Ali' like 'Z% A_i' returns a Boolean false. |
BETWEEN | The BETWEEN operator tests whether a value lies in a specified range. x BETWEEN a AND b means that x >= a and x ⇐ b. | If x = 10 then, x between 5 and 20 returns true, x between 5 and 10 returns true, but x between 11 and 20 returns false. |
IN | The IN operator tests set membership. x IN (set) means that x is equal to any member of set. | If x = 'm' then, x in ('a', 'b', 'c') returns Boolean false but x in ('m', 'n', 'o') returns Boolean true. |
IS NULL | The IS NULL operator returns the BOOLEAN value TRUE if its operand is NULL or FALSE if it is not NULL. Comparisons involving NULL values always yield NULL. | If x = 'm', then 'x is null' returns Boolean false. |
論理演算子
次の表に、PL/SQLでサポートされる論理演算子を示します。 これらの演算子はすべてブール値オペランドで機能し、ブール値の結果を生成します。 *変数A *がtrueを保持し、*変数B *がfalseを保持すると仮定してみましょう-
リンク:/plsql/plsql_logical_operators [例を表示]
Operator | Description | Examples |
---|---|---|
and | Called the logical AND operator. If both the operands are true then condition becomes true. | (A and B) is false. |
or | Called the logical OR Operator. If any of the two operands is true then condition becomes true. | (A or B) is true. |
not | Called the logical NOT Operator. Used to reverse the logical state of its operand. If a condition is true then Logical NOT operator will make it false. | not (A and B) is true. |
PL/SQL演算子の優先順位
演算子の優先順位は、式内の用語のグループ化を決定します。 これは、式の評価方法に影響します。 特定の演算子は、他の演算子よりも優先順位が高くなっています。たとえば、乗算演算子は加算演算子よりも優先順位が高くなります。
たとえば、 x = 7 + 3 2 ;ここでは、演算子*の優先順位が+より高いため、 *x には20ではなく 13 が割り当てられます。したがって、最初に 3 2 で乗算され、 *7 に加算されます。
ここでは、優先順位が最も高い演算子が表の上部に表示され、優先順位が最も低い演算子が下部に表示されます。 式内では、優先順位の高い演算子が最初に評価されます。
演算子の優先順位は、=、<、>、⇐、> =、<>、!=、〜=、^ =、IS NULL、LIKE、BETWEEN、INです。
リンク:/plsql/plsql_operators_precedence [例を表示]
Operator | Operation |
---|---|
** | exponentiation |
+, - | identity, negation |
*,/ | multiplication, division |
+, -, | |
addition, subtraction, concatenation | |
comparison | |
NOT | logical negation |
AND | conjunction |
OR | inclusion |