Reputation: 61
Consider there are two columns named StartDate
,EndDate
(2017/03/09 11:25:02
, 2018/08/10 15:20:03
) in sql
.
I need to get the DurationDate
column(number of years
, months
, days
, hours
, minutes
, seconds
) should be automatically updated in the duration column based on StartDate
and EndDate
in the sql
table.
Upvotes: 1
Views: 44
Reputation: 1269753
Since Oracle 11g, you can use generated columns:
alter table t add duration as (EndDate - StartDate);
This will produce an interval result if the two "dates" are stored as timestamps
. The difference of two dates is a number of decimal days.
In earlier versions, you need to use views to accomplish the same thing.
Upvotes: 3