I have a start_session and end_session.
I want to make sure with a constraint that the end_session is 60 minutes after the start_session.
Is this possible, something like the following
ALTER TABLE BOOKING_SESSION ADD CONSTRAINT SESSION_LENGHT CHECK (END_SESSION > START_SESSION + 60 MINUTES );
I got the following trigger to check that the start session is not bigger than the end session (thanks to Justin Cave)
CREATE OR REPLACE TRIGGER trg_check_dates
BEFORE INSERT OR UPDATE ON BOOKING_SESSION
FOR EACH ROW
BEGIN
IF( :NEW.END_SESSION < :NEW.START_SESSION )
THEN
RAISE_APPLICATION_ERROR( -20001,
'Invalid: END_SESSION must be greater than START_SESSION = ' ||
to_char( :NEW.START_SESSION, 'YYYY-MM-DD HH24:MI:SS' ));
END IF;
END;
/
However i need the one that makes sure that the end session is one hour after the start_session
Here is how the
Checkconstraint can be used to impose that kind of restriction:In the example above
start_sessionandend_sessioncolumns are oftimestampdatatype. If you have them declared asDatedatatype then formula for thecheckconstraint might be: