check date value range : Date « Data Type « Oracle PL / SQL






check date value range

     
SQL>
SQL> CREATE OR REPLACE FUNCTION date_range
  2     (p_low_end_date  DATE,
  3      p_high_end_date DATE,
  4      p_to_check_date DATE)
  5      RETURN BOOLEAN IS
  6
  7      returnBoolean BOOLEAN := FALSE;
  8      smallDate   DATE := TRUNC(p_low_end_date); -- Time 00:00:00
  9      largeDate  DATE := TRUNC(p_high_end_date + 1) - .000011574;
 10  BEGIN
 11     IF p_to_check_date >  smallDate  AND
 12        p_to_check_date <= largeDate THEN
 13        returnBoolean := TRUE;
 14     END IF;
 15
 16     DBMS_OUTPUT.PUT_LINE('Low Date     : ' || TO_CHAR(smallDate, 'MM/DD/YYYY:HH24:MI:SS'));
 17     DBMS_OUTPUT.PUT_LINE('Date To Check: ' || TO_CHAR(p_to_check_date, 'MM/DD/YYYY:HH24:MI:SS'));
 18     DBMS_OUTPUT.PUT_LINE('High Date    : ' || TO_CHAR(largeDate,    'MM/DD/YYYY:HH24:MI:SS'));
 19     RETURN returnBoolean;
 20  END date_range;
 21  /

Function created.

SQL>
SQL> SET SERVEROUTPUT ON SIZE 1000000
SQL> DECLARE
  2     checkBoolean BOOLEAN;
  3  BEGIN
  4     checkBoolean := date_range(SYSDATE, SYSDATE, SYSDATE);
  5     IF checkBoolean THEN
  6        DBMS_OUTPUT.PUT_LINE('Date in Range: TRUE');
  7     ELSE
  8        DBMS_OUTPUT.PUT_LINE('Date in Range: FALSE');
  9    END IF;
 10  END;
 11  /
Low Date     : 06/19/2008:00:00:00
Date To Check: 06/19/2008:18:55:03
High Date    : 06/19/2008:23:59:59
Date in Range: TRUE

PL/SQL procedure successfully completed.

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.Insert statement converts text value to date type value
9.Are two dates equal
10.Use comparison operator with date type value
11.Compare date value after to_char() and trim()
12.Compare date value with sysdate or null value
13.Use to_char to format date
14.use to_char more than once to create long date format
15.Declare date type variable and set the value at the same time
16.Differences Between Dates
17.Extract year, month, day from a date
18.Insert sysdate value to date type column
19.Use if statement to compare two date type variable
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