The INTERVAL data type in Oracle is used to represent time intervals. The syntax is INTERVAL
. You can use addition, subtraction, multiplication and division operations to operate INTERVAL, which is suitable for storing time data and calculating date differences. Worth waiting for the scene.
Usage of INTERVAL in Oracle
In Oracle, the INTERVAL data type is used to represent time intervals. It's great for storing and manipulating time data.
Syntax for INTERVAL
INTERVAL <精度> <单位>
Copy after login
Where:
UnitSpecify the unit of the time interval, which can be:
Create INTERVAL
You can create INTERVAL using the following syntax:
CAST(<值> AS INTERVAL <单位>)
For example:
CAST('1' AS INTERVAL YEAR) -- 创建一个间隔 1 年的值 CAST('-2' AS INTERVAL MONTH) -- 创建一个间隔 2 个月的负值
Operation INTERVAL
INTERVAL can be operated on using arithmetic operators:
For example:
INTERVAL '1' YEAR + INTERVAL '3' MONTH -- 增加一个时间间隔,间隔为 1 年 3 个月 INTERVAL '2' DAY - INTERVAL '1' DAY -- 减小一个时间间隔,间隔为 1 天 3 * INTERVAL '1' HOUR -- 将时间间隔乘以 3,间隔为 3 小时 INTERVAL '1' DAY / 2 -- 将时间间隔除以 2,间隔为 12 小时
USE INTERVAL
INTERVAL can be used for many purposes, including:
The above is the detailed content of How to use interval in oracle. For more information, please follow other related articles on the PHP Chinese website!