Results 1 to 4 of 4

Thread: Date validation

  1. #1
    Join Date
    Jul 2005
    Posts
    29

    Unanswered: Date validation

    Hi,
    I'd like validate date in varchar format.
    create or replace f_check_date(dat in varchar2(10))
    RETURN BOOLEAN
    IS
    lv_date date;
    BEGIN
    lv_date := to_date(input_date,'dd.mon.yyyy');
    Return true;
    EXCEPTION
    when others then
    RETURN FALSE;
    END;
    /

    How can I do it?

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    >How can I do it?
    What is wrong with what you have?
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Jul 2005
    Posts
    29
    sorry my edit mistake

    this:
    create or replace function f_check_date(datum IN VARCHAR2(10))
    RETURN BOOLEAN
    IS
    v_datum varchar2(10) := '';
    BEGIN
    v_datum := to_date(datum,'dd.mm.yyyy');
    RETURN TRUE;
    EXCEPTION
    when others then
    RETURN FALSE;
    END;
    /

    ERROR at line 1: PLS-00103: Encountered the symbol "(" when expecting one of the following: := . ) , @ % default character The symbol ":=" was substituted for "(" to continue.
    Last edited by Perseus; 12-10-06 at 05:37.

  4. #4
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    This example could help ... perhaps. I'm returning a NUMBER (instead of BOOLEAN as it is easier to test it - being too lazy to write another PL/SQL which will catch BOOLEAN).
    Code:
    CREATE OR REPLACE FUNCTION F_Check_Date  (dat IN CHAR)
      RETURN NUMBER IS
      l_result NUMBER;  
    BEGIN
      SELECT MONTHS_BETWEEN(TO_DATE(dat, 'dd.mm.yyyy'), SYSDATE)
        INTO l_result
        FROM dual;
    
      RETURN (1);
      EXCEPTION
        WHEN OTHERS THEN RETURN (0);
    END;
    Code:
    SQL> select f_check_date('2006.11.16') is_it_ok from dual;
    
      IS_IT_OK
    ----------
             0
    
    SQL> select f_check_date('10.11.2006') is_it_ok from dual;
    
      IS_IT_OK
    ----------
             1
    
    SQL>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •