Use if statement to compare two date type variable : Date « Data Type « Oracle PL / SQL






Use if statement to compare two date type variable

    
SQL> -- create demo table
SQL> create table emp(
  2    ID                 VARCHAR2(4 BYTE)         NOT NULL,
  3    fname         VARCHAR2(10 BYTE),
  4    lname          VARCHAR2(10 BYTE),
  5    Start_Date         DATE,
  6    End_Date           DATE,
  7    Salary             Number(8,2),
  8    City               VARCHAR2(10 BYTE),
  9    Description        VARCHAR2(15 BYTE)
 10  )
 11  /

Table created.

SQL>
SQL>
SQL>
SQL> -- prepare data
SQL> insert into emp(ID,  fname, lname, Start_Date,                     End_Date
,                       Salary,  City,       Description)
  2               values ('01','Jason',    'Martin',  to_date('19960725','YYYYMM
DD'), to_date('20060725','YYYYMMDD'), 1234.56, 'Toronto',  'Programmer')
  3  /

1 row created.

SQL> insert into emp(ID,  fname, lname, Start_Date,                     End_Date
,                       Salary,  City,       Description)
  2                values('02','Alison',   'Mathews', to_date('19760321','YYYYMM
DD'), to_date('19860221','YYYYMMDD'), 6661.78, 'Vancouver','Tester')
  3  /

1 row created.

SQL>
SQL>
SQL> declare
  2    dateValue date;
  3    s Number(8,2);
  4    begin
  5         select start_date into dateValue from emp where rownum = 1;
  6         select salary into s from emp where rownum = 1;
  7
  8          IF dateValue > '11-APR-63' then
  9              s :=  s * 1.15;
 10          END IF;
 11
 12
 13       dbms_output.put_line(s);
 14  end;
 15  /
1419.74

PL/SQL procedure successfully completed.

SQL>
SQL> drop table emp;

Table dropped.

SQL>

   
    
    
    
  








Related examples in the same category

1.Define and use Date data type
2.Date data types
3.Use DATE type column
4.Use DATE to mark a string as date value
5.Use SYSDATE in insert statement
6.Initialize value with date functions
7.Set date value to SYSDATE
8.check date value range
9.Insert statement converts text value to date type value
10.Are two dates equal
11.Use comparison operator with date type value
12.Compare date value after to_char() and trim()
13.Compare date value with sysdate or null value
14.Use to_char to format date
15.use to_char more than once to create long date format
16.Declare date type variable and set the value at the same time
17.Differences Between Dates
18.Extract year, month, day from a date
19.Insert sysdate value to date type column
20.Assign system date to date type variable
21.Date math
22.Date type column
23.Date value calculation in to_char function
24.Date variable
25.Date/Time literals
26.New ANSI DATE literal.
27.Store hour:minute information to date type variable
28.Assign date value as string to date type variable
29.Convert the character string back to date format