Search code examples
sqloracleoracle-sqldeveloper

adding a min and max date and getting error: literal does not match format string


I am trying to create a table for bookings and want there to be a check constraint where the customer can only insert the D.O.B from a certain year to another certain year but keep getting the same error message

Any help would be very appreciated

`

create table guest
( Guest_ID      varchar2(8)       primary key, 
 Family_Name    varchar2(20)      not null,
 Given_Name     varchar2(20)      not null,
 Date_of_Birth  date              check (Date_of_Birth between date '01/01/1904' and 
                                         date '01/01/2004' ) not null,
 Address        varchar2(80)      not null
); 

`


Solution

  • Use the following code:

    create table guest
    ( Guest_ID      varchar2(8)       primary key, 
     Family_Name    varchar2(20)      not null,
     Given_Name     varchar2(20)      not null,
     Date_of_Birth  date              check (Date_of_Birth between to_date('01/01/1904','DD/MM/YYYY') and 
                                             to_date('01/01/2004','DD/MM/YYYY')) not null,
     Address        varchar2(80)      not null
    );