OceanBase logo

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Resources

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS

OceanBase Cloud

OceanBase Database

Tools

Connectors and Middleware

QUICK START

OceanBase Cloud

OceanBase Database

BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Company

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

International - English
中国站 - 简体中文
日本 - 日本語
Sign In
Start on Cloud

A unified distributed database ready for your transactional, analytical, and AI workloads.

DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS
OceanBase CloudOceanBase Database
ToolsConnectors and Middleware
QUICK START
OceanBase CloudOceanBase Database
BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

Start on Cloud
编组
All Products
    • Databases
    • iconOceanBase Database
    • iconOceanBase Cloud
    • iconOceanBase Tugraph
    • iconInteractive Tutorials
    • iconOceanBase Best Practices
    • Tools
    • iconOceanBase Cloud Platform
    • iconOceanBase Migration Service
    • iconOceanBase Developer Center
    • iconOceanBase Migration Assessment
    • iconOceanBase Admin Tool
    • iconOceanBase Loader and Dumper
    • iconOceanBase Deployer
    • iconKubernetes operator for OceanBase
    • iconOceanBase Diagnostic Tool
    • iconOceanBase Binlog Service
    • Connectors and Middleware
    • iconOceanBase Database Proxy
    • iconEmbedded SQL in C for OceanBase
    • iconOceanBase Call Interface
    • iconOceanBase Connector/C
    • iconOceanBase Connector/J
    • iconOceanBase Connector/ODBC
    • iconOceanBase Connector/NET
icon

OceanBase Database

SQL - V4.2.0

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogLive DemosTraining & Certification
    Company
    About OceanBaseTrust CenterLegalPartnerContact Us
    Follow Us

    © OceanBase 2026. All rights reserved

    Cloud Service AgreementPrivacy PolicySecurity
    Contact Us
    Document Feedback
    1. Documentation Center
    2. OceanBase Database
    3. SQL
    4. V4.2.0
    iconOceanBase Database
    SQL - V 4.2.0
    SQL
    KV
    • V 4.4.2
    • V 4.3.5
    • V 4.3.3
    • V 4.3.1
    • V 4.3.0
    • V 4.2.5
    • V 4.2.2
    • V 4.2.1
    • V 4.2.0
    • V 4.1.0
    • V 4.0.0
    • V 3.1.4 and earlier

    Interval literals

    Last Updated:2023-10-31 11:17:11  Updated
    share
    What is on this page
    Leading field and trailing field
    INTERVAL YEAR TO MONTH literal
    INTERVAL DAY TO SECOND literal

    folded

    share

    An interval literal specifies a period of time. OceanBase Database supports two types of interval literals: INTERVAL YEAR TO MONTH and INTERVAL DAY TO SECOND.

    Leading field and trailing field

    Each type of interval literals contains a leading field and may contain a trailing field. The leading field defines the basic unit of the date or time that is being measured. The trailing field defines the minimum increment of the basic unit.

    For example, DAY TO SECOND specifies an interval literal with a basic unit of days, where the leading field is DAY and the trailing field is SECOND. The trailing field is optional and can be omitted when you specify an interval literal.

    Fields available in the interval literals include YEAR, MONTH, DAY, HOUR, MINUTE, and SECOND. The weight of these fields decreases from YEAR. When you specify the trailing field, make sure that the weight of the trailing field is lower than that of the leading field. Otherwise, the specified trailing field is invalid. For example, INTERVAL '1-2' DAY TO YEAR is an invalid literal.

    The value range of the number of digits of the leading field value is [0,9]. The default value is 2. The SECOND field specifies the number of seconds. The value can be accurate to 0 to 9 decimal places after the decimal point. By default, the value is accurate to 6 decimal places after the decimal point. If the value of this field exceeds the precision range, an error is returned. If the number of decimal digits in the SECOND field value exceeds the specified precision range, the field value will be rounded to the specified precision.

    INTERVAL YEAR TO MONTH literal

    The INTERVAL YEAR TO MONTH literal specifies a period of time in years and months.

    The following table lists some INTERVAL YEAR TO MONTH literals.

    Example Description
    INTERVAL '265-2' YEAR(3) TO MONTH Indicates an interval of 265 years and 2 months. The value of the YEAR leading field exceeds the default precision 2. In this example, the precision must be specified as 3.
    INTERVAL '265' YEAR(3) Indicates an interval of 265 years.
    INTERVAL '500' MONTH(3) Indicates an interval of 500 months or 41 years and 8 months.
    INTERVAL '10' MONTH Indicates an interval of 10 months.
    INTERVAL '123' YEAR An error is returned, because the field value 123 exceeds the default precision 2.

    You can add an INTERVAL YEAR TO MONTH literal to or subtract it from another INTERVAL YEAR TO MONTH literal. For example, INTERVAL '6-2' YEAR TO MONTH + INTERVAL'21' MONTH = INTERVAL '7-11' YEAR TO MONTH.

    INTERVAL DAY TO SECOND literal

    The INTERVAL DAY TO SECOND literal specifies a period of time in days and seconds.

    The following table lists some INTERVAL DAY TO SECOND literals.

    Example Description
    INTERVAL '4 5:12:10.222' DAY TO SECOND(3) Indicates an interval of 4 days, 5 hours, 12 minutes, and 10.222 seconds. The default precision of the SECOND field value is 6 decimal places after the decimal point. In this example, the precision is manually specified as 3 decimal places after the decimal point. Otherwise, 0 is added after the decimal in the returned result to meet the requirement of 6 decimal places.
    INTERVAL '4 5:12' DAY TO MINUTE Indicates an interval of 4 days, 5 hours, and 12 minutes.
    INTERVAL '400 5' DAY(3) TO HOUR Indicates an interval of 400 days and 5 hours. The value of the leading field DAY exceeds the default precision 2. In this example, the precision is manually specified as 3.
    INTERVAL '400' DAY(3) Indicates an interval of 400 days.
    INTERVAL '11:12:10.2222222' HOUR TO SECOND(7) Indicates an interval of 11 hours, 12 minutes, and 10.2222222 seconds. The value of the leading field SECOND exceeds the default precision of 6 decimal places after the decimal point. In this example, the precision is manually specified as 7 decimal places after the decimal point.
    INTERVAL '11:20' HOUR TO MINUTE Indicates an interval of 11 hours and 20 minutes.
    INTERVAL '10' HOUR Indicates an interval of 10 hours.
    INTERVAL '10:22' MINUTE TO SECOND Indicates an interval of 10 minutes and 22 seconds.
    INTERVAL '10' MINUTE Indicates an interval of 10 minutes.
    INTERVAL '4' DAY Indicates an interval of 4 days.
    INTERVAL '25' HOUR Indicates an interval of 25 hours.
    INTERVAL '40' MINUTE Indicates an interval of 40 minutes.
    INTERVAL '120' HOUR(3) Indicates an interval of 120 hours.
    INTERVAL '30.12345' SECOND(2,4) Indicates an interval of 30.1235 seconds. The number of decimal places after the decimal point in SECOND exceeds the default precision and the field value is rounded to the fourth place after the decimal point.

    You can add an INTERVAL DAY TO SECOND literal to or subtract it from another INTERVAL DAY TO SECOND literal. For example, INTERVAL'20' DAY - INTERVAL'239' HOUR = INTERVAL'10-1' DAY TO SECOND.

    Previous topic

    Timestamp literals
    Last

    Next topic

    Overview
    Next
    What is on this page
    Leading field and trailing field
    INTERVAL YEAR TO MONTH literal
    INTERVAL DAY TO SECOND literal