21. 6. 1. DATE |
|
The DATE datatype is used to store date and time values. |
The time component is always there whether you use it or not. |
The range for date variables is from 1 Jan 4712 BC through 31 Dec 4712 AD. |
If you do not specify a time when assigning a value to a variable of type DATE, it will default to midnight (12:00:00 a.m.). |
The Syntax for the DATE Datatype |
|
Here are some examples: |
hire_date DATE;
emp_birthdate DATE;
|
|
Use the following code to declare the DATE datatype: |
SQL> declare
2 variable1_dt DATE;
3 begin
4 NULL;
5 end;
6 /
PL/SQL procedure successfully completed.
|
|
Be careful when comparing dates. |
If you really don't care about the time of day, you can use the TRUNC() function. |
For example, instead of |
IF hire_date = fire_date THEN...
|
|
use |
IF TRUNC(hire_date) = TRUNC(fire_date) THEN...
|
|