SQL> -- Date comparison example.
SQL> SET SERVEROUTPUT ON
SQL>
SQL> DECLARE
2 payment_due_date DATE;
3 BEGIN
4 payment_due_date := TO_DATE('1-Jun-1997','dd-mon-yyyy');
5
6 DBMS_OUTPUT.PUT_LINE('Today is ' || TO_CHAR(SYSDATE,'dd-Mon-yyyy'));
7 DBMS_OUTPUT.PUT_LINE('Payment is due on ' || TO_CHAR(payment_due_date,'dd-Mon-yyyy'));
8
9 IF payment_due_date = SYSDATE THEN
10 DBMS_OUTPUT.PUT_LINE('Payment is due today.');
11 ELSE
12 DBMS_OUTPUT.PUT_LINE('Payment can wait a while.');
13 END IF;
14
15 IF TRUNC(payment_due_date) = TRUNC(SYSDATE) THEN
16 DBMS_OUTPUT.PUT_LINE('Wrong! Payment is due today!');
17 ELSE
18 DBMS_OUTPUT.PUT_LINE('Wrong! Payment can wait a while.');
19 END IF;
20 END;
21 /
Today is 31-Aug-2006
Payment is due on 01-Jun-1997
Payment can wait a while.
Wrong! Payment can wait a while.
PL/SQL procedure successfully completed.
SQL>
SQL>
|