# PL/SQL關係運算子

2019-10-16 22:54:20

`=` 檢查兩個運算元的值是否相等，如果是，則條件成立。 (A = B)為假
`!=`,`<>``~=` 檢查兩個運算元的值是否相等，如果兩個值不相等則條件成為真。 (A != B)為真
`>` 檢查左運算元的值是否大於右運算元的值，如果是，則條件成為真。 (A > B) 為假
`<` 檢查左運算元的值是否小於右運算元的值，如果是，則條件成為真。 (A < B) 條件為真。
`>=` 檢查左運算元的值是否大於或等於右運算元的值，如果是，則條件成為真。 (A >= B) 為假
`<=` 檢查左運算元的值是否小於或等於右運算元的值，如果是，則條件成為真。 (A <= B) 為真

``````DECLARE
a number (2) := 21;
b number (2) := 10;
BEGIN
IF (a = b) then
dbms_output.put_line('Line 1 - a is equal to b');
ELSE
dbms_output.put_line('Line 1 - a is not equal to b');
END IF;
IF (a < b) then
dbms_output.put_line('Line 2 - a is less than b');
ELSE
dbms_output.put_line('Line 2 - a is not less than b');
END IF;

IF ( a > b ) THEN
dbms_output.put_line('Line 3 - a is greater than b');
ELSE
dbms_output.put_line('Line 3 - a is not greater than b');
END IF;
-- Lets change value of a and b
a := 5;
b := 20;
IF ( a <= b ) THEN
dbms_output.put_line('Line 4 - a is either equal or less than b');
END IF;
IF ( b >= a ) THEN
dbms_output.put_line('Line 5 - b is either equal or greater than a');
END IF;
IF ( a <> b ) THEN
dbms_output.put_line('Line 6 - a is not equal to b');
ELSE
dbms_output.put_line('Line 6 - a is equal to b');
END IF;
END;
/
``````

``````Line 1 - a is not equal to b
Line 2 - a is not less than b
Line 3 - a is greater than b
Line 4 - a is either equal or less than b
Line 5 - b is either equal or greater than a
Line 6 - a is not equal to b

PL/SQL procedure successfully completed
``````