# Expressions and Comparisons

constant. 100 + (20 / 5 + (7 . literal Operators = +.Expressions and Comparisons Expressions are constructed using operands and operators Operand=variable.3)) . !=. >. *. || =. BETWEEN. concatenation comparison conjunction inclusion 12 / 4 + 5.. LIKE. (8 + 6) / 2. negation multiplication. ^=. IS NULL. IN AND OR Operation exponentiation. division addition. ~=. >=.etc Operator Precedence Operator **. logical negation identity. NOT +. <>. -. / +. <=. <. subtraction.

NOT is a unary operator. x TRUE TRUE TRUE FALSE FALSE FALSE NULL NULL NULL y TRUE FALSE NULL TRUE FALSE NULL TRUE FALSE NULL x AND y TRUE FALSE NULL FALSE FALSE FALSE NULL FALSE NULL x OR y TRUE TRUE TRUE TRUE FALSE NULL TRUE NULL NULL NOT Y FALSE TRUE NULL . and NOT follow the tri-state logic shown in Table AND and OR are binary operators. OR.Logical Operators The logical operators AND.

it is a poor programming practice to rely on short-circuit evaluation. END. .. the left operand yields TRUE. on_hand INTEGER. BEGIN . so PL/SQL need not evaluate the right operand.Short-Circuit Evaluation DECLARE ... IF (on_hand = 0) OR ((on_order / on_hand) < 5) THEN END IF. If PL/SQL were to evaluate both operands before applying the OR operator. . In any case. the right operand would cause a division by zero error... When the value of on_hand is zero. on_order INTEGER.

. or null. ELSE . Company Logo .Comparison Operators  Comparison operators compare one expression to another. END IF.1 WHERE part_number = item_number. false.. Typically. The result is always true. you use comparison operators in conditional control statements and in the WHERE clause of SQL data manipulation statements. Here are a couple of examples: IF quantity_on_hand > 0 THEN UPDATE inventory SET quantity = quantity .

.Relational Operators Operator = <>. FALSE. An underscore (_) matches exactly one character.. Instead.. the following expression is true: number1 > number2 . use the following statement: IF variable IS NULL THEN . LIKE Operator ename LIKE 'J%SON‘(wildcards. ~=. 'KING'.number2:= 70.org Meaning equal to not equal to less than greater than less than or equal to greater than or equal to IS NULL Operator IF variable = NULL THEN . Concatenation Operator 'suit' || 'case‘ Boolean Expressions TRUE. 'FORD').. !=. ^= < > <= >= www. or NULL.desinfreebies. Arithmetic Expressions number1:= 75. a percent sign (%)) BETWEEN Operator 45 BETWEEN 38 AND 44 IN Operator DELETE FROM emp WHERE ename IN (NULL.

org Character Expressions string1:= 'Kathy'. the following expression is true: string1 > string2 Date Expressions date1:= '01-JAN-91'..date2:= '31-DEC-90'.designfreebies.. can be simplified as follows: WHILE NOT done LOOP .END LOOP.illegal The debugged version follows: (100 < tax) AND (tax < 500) Boolean variable WHILE NOT (done = TRUE) LOOP ..END LOOP.string2:= 'Kathleen'.www. . the following expression is true: date1 > date2 Note: 100 < tax < 500 -..

designfreebies.org Thank You ! .www.