基本述詞 (basic predicate)

基本述詞 會比較兩個值,或比較一組值與另一組值。

Read syntax diagramSkip visual syntax diagramexpressioncomparison-operatorexpressionrow-value-expressioncomparison-operatorrow-value-expressionboolean-expression
comparison-operator
Read syntax diagramSkip visual syntax diagram =  <> 1 <  >  <= 1 >= 1
Notes:

6 個比較運算子可以有效地根據其中 2 個比較運算子來表示。 如果述詞運算元為 xy,則可以使用下列替代述詞來表示其他四個比較運算子。

表 1. 述詞和替代述詞
述詞 替代述詞
x <> y NOT (x = y)
x > y y < x
x <= y x < y OR x = y
x >= y y < x OR x = y

當述詞運算元指定為 表示式時,表示式的資料類型必須是可比較的。 如果任一運算元的值是空值,則述詞的結果不明。 否則結果為 true 或 false。

表 2. 具有純量運算元的述詞評估
述詞 (含運算元值 xy) Boolean 值 如果且僅當 ...
x = y 是 true x 等於 y
x < y 是 true x 小於 y
x = y 是 false x 不等於 y
x < y 是 false x = y 是 True 或 y < x 是 True

當述詞運算元指定為 row-value-expression時,它們必須具有相同的欄位數,且運算元對應欄位的資料類型必須是可比較的。 比較結果基於 row-value-expression 運算元中對應欄位的比較。

表 3. 具有列運算元的述詞評估
Predicate (with operand values Rx and that have fields Rxi and where 0 < < 欄位數) Boolean 值 如果且僅當 ...
Rx = Ry 是 true 對應值表示式的所有配對都相等 (Rxi = 對於 的所有值都是 True)。
Rx < Ry 是 true 對應值表示式的第一個 N 配對相等,下一個配對的左值表示式小於 N 部分值的右值表示式 (Rxi = 對於 < n 的所有值為 True , Rxn < 對於 n的部分值為 True)。
Rx = Ry 是 false 至少一對對應值表示式不相等 (NOT (Rxi = Ryi) 對於 i)。
Rx < Ry 是 false All pairs of corresponding value expressions are equal (Rx = is True) or the first N pairs of corresponding value expressions are equal and the next pair has the right value expression less than the left value expression for some value of N (Rxi = is True for all values of < n and < Rxn is True for some value of n).
Rx comparison operator Ry 不明 比較既不是 True 也不是 False。

布林值

您可以使用基本述詞來比較 布林值 與另一個布林值,或與可強制轉型為布林值的資料類型值。 TRUE 值大於 FALSE 值。 例如:
  • TRUE = 'on' 是 true
  • DECFLOAT(4.3) = TRUE 是 true
  • '0' <= FALSE 是 true
  • 'yes' <= FALSE 是 false

替代表單

For the comparison operators <>, <=, and >=, alternative forms are also supported. (The forms ¬=, ¬<, and ¬> are supported only in code pages 437, 819, and 850.) 對這些替代表單的支援僅旨在容納現有的 SQL 陳述式; 不建議對新的 SQL 陳述式使用這些表單。

比較運算子 替代表單
<> ^= != ¬=
<= ^> !> ¬>
>= ^< !< ¬<

範例:

   EMPNO='528671'  
   SALARY < 20000 
   PRSTAFF <> :VAR1
   SALARY > (SELECT AVG(SALARY) FROM EMPLOYEE)
  (YEARVAL, MONTHVAL) >= (2009, 10)