Oracle PL/SQL - PL SQL Operator Arithmetic Comparisons

Introduction

One number is greater than another if it represents a larger value.

Real numbers are stored as approximate values, so you should compare them for equality or inequality.

The following code shows how to use relational operators to compare arithmetic values.

Demo

SQL>
SQL> CREATE OR REPLACE PROCEDURE print_boolean (
  2    b_name   VARCHAR2,--  ww w  . j  a  v  a2  s.  c o m
  3    b_value  BOOLEAN
  4   ) IS
  5  BEGIN
  6    IF b_value IS NULL THEN
  7      DBMS_OUTPUT.PUT_LINE (b_name || ' = NULL');
  8    ELSIF b_value = TRUE THEN
  9      DBMS_OUTPUT.PUT_LINE (b_name || ' = TRUE');
 10    ELSE
 11      DBMS_OUTPUT.PUT_LINE (b_name || ' = FALSE');
 12    END IF;
 13  END;
 14  /

Procedure created.

SQL> BEGIN
  2    print_boolean ('(2 + 2 =  4)', 2 + 2 = 4);
  3
  4    print_boolean ('(2 + 2 <> 4)', 2 + 2 <> 4);
  5    print_boolean ('(2 + 2 != 5)', 2 + 2 != 5);
  6    print_boolean ('(2 + 2 ~= 4)', 2 + 2 ~= 4);
  7    print_boolean ('(2 + 2 ^= 4)', 2 + 2 ^= 4);
  8
  9    print_boolean ('(1 < 2)', 1 < 2);
 10    print_boolean ('(1 > 2)', 1 > 2);
 11    print_boolean ('(1 <= 2)', 1 <= 2);
 12    print_boolean ('(1 >= 1)', 1 >= 1);
 13  END;
 14  /
(2 + 2 =  4) = TRUE
(2 + 2 <> 4) = FALSE
(2 + 2 != 5) = TRUE
(2 + 2 ~= 4) = FALSE
(2 + 2 ^= 4) = FALSE
(1 < 2) = TRUE
(1 > 2) = FALSE
(1 <= 2) = TRUE
(1 >= 1) = TRUE

PL/SQL procedure successfully completed.

SQL>

Related Topic