Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with time

Status
Not open for further replies.

Jphillis

Technical User
Jun 27, 2001
19
0
0
GB
I have a start and a finish time. I want to ensure that the end user cannot insert a finish time that is less than the start time.
eg
Start time 10:50 Finish time 10:40
I want to make it either impossible to do the above or to bring up an exception, which ever is easiest.
 
The easiest way to do this is to define a check constraint on your table.

alter table your_table add constraint check_times check (start_time < finish_time);

Then if your data violates this constraint, the update or insert will fail with an ORA-02290: check constraint (CHECK_TIMES) violated.

There may be issues with null values, if either of these columns allows nulls.
 
I have inserted the line of code as follows 'CONSTRAINT check_times check (start_time < finish_time)', however i get an error saying 'missing or invalid operation' what am i doing wrong?
 

The solution you're trying is OK.
But the command you've mentioned is not complete.
Syntax can be reviewed in SQL*PLUS Manual.

Syntax will look like the following, but without the quotes
'ALTER TABLE your_table ADD CONSTRAINT check_times check (start_time < finish_time);'


P.S. Oracle stores dates with hours, minutes & seconds.
 
Are the start_time and finish_time DATE columns? I assume they are. To enter a time into a date column you have to do something like:

INSERT INTO table (
start_time,
finish_time )
VALUES (
To_Date:)user_start_time,'HH24:MI'),
To_Date:)user_finish_time,'HH24:MI') );

If the colums are VARCHAR2, then be aware that '10:30' is greater than '09:30', but '10:30' is less than '9:30' in a varchar column.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top