Mega Code Archive

 
Categories / Oracle PLSQL Tutorial / PL SQL Statements
 

Handling conditions

Conditions can be connected by using logical operations: AND, OR, and NOT. The default order of evaluation is standard. First any parentheses are resolved. Then operators are executed on the same level in order of precedence: NOT (highest precedence), AND, and OR (lowest precedence). SQL> declare   2      v_day NUMBER := TO_CHAR(TO_DATE('20060101','YYYYMMDD'),'D');   3  begin   4      if v_day in (1,7) or (v_day not in (1,7) and (v_day between 0 and 6 or v_day between 19 and 23))   5      then   6          DBMS_OUTPUT.put_line(v_day||': Off-peak');   7      else   8          DBMS_OUTPUT.put_line(v_day||': Peak');   9      end if;  10  end;  11  / 1: Off-peak PL/SQL procedure successfully completed. SQL>