The INTERVAL type in Oracle is used to represent a time period, including time units (such as days, hours) and time quantities (such as 3, 10); it is often used to calculate the difference between date or time values. The syntax is INTERVAL time_value time_unit, where time_value is the time quantity and time_unit is the time unit, such as YEAR, MONTH, DAY, etc.; for example, calculate the number of days between two dates: SELECT INTERVAL '2023-06-15' - '2023-05 -15' DAY FROM DUAL;
INTERVAL type in Oracle
INTERVAL type is used to represent a time period or Date range. It contains the following two parts:
Usage
INTERVAL type is generally used to calculate the difference between date or time values. The syntax is as follows:
<code>INTERVAL time_value time_unit</code>
Where:
time_value
is the time quantity, which can be a positive or negative number. time_unit
is the time unit and can be the following values:
YEAR
MONTH
Example
The following example shows some uses of the INTERVAL type:<code>-- 计算两个日期之间的天数 SELECT INTERVAL '2023-06-15' - '2023-05-15' DAY FROM DUAL;</code>Output:
<code>31</code>
<code>-- 计算当前时间到指定时间的分钟数 SELECT INTERVAL TIMESTAMP '2023-06-15 10:30:00' - CURRENT_TIMESTAMP MINUTE FROM DUAL;</code>Output:
<code>25</code>
<code>-- 根据天数创建一个 INTERVAL SELECT INTERVAL 30 DAY FROM DUAL;</code>Output:
<code>30 DAY</code>
Notes
The above is the detailed content of interval usage in oracle. For more information, please follow other related articles on the PHP Chinese website!