In Oracle Database, there is a wide range of data types available to store different types of data. One such datatype is Datetime.
The most recent version of the well-known database management system utilised by companies around the globe is called Oracle 21c. The Datetime datatype in Oracle 21c is among the most significant data types. This data type is a fundamental part of many database systems and is required for working with dates and times in Oracle. This essay will go into great detail about the Oracle 21c Datetime datatype.
Introduction to Oracle Datetime Datatype
In Oracle 21c, dates and times are stored in databases using the Datetime datatype. Date and time data can be formatted, subjected to mathematical operations, and subjected to comparisons thanks to this data type. In a database, dates, timings, and timestamps are stored using the Datetime datatype.
The Datetime datatype can be divided into three subtypes in Oracle 21c:
- Dates and times are kept in databases using the DATE subtype. The year, month, day, hour, minute, and second are all included in the predefined format of the DATE datatype, which also retains the date and time information.
- TIMESTAMP: Information about date and time that includes fractional seconds is stored using the TIMESTAMP subtype. Dates and timings can be stored using the TIMESTAMP datatype down to the millisecond level.
- INTERVAL: A database can hold time intervals using the INTERVAL subtype. Time intervals measured in years, months, days, hours, minutes, and seconds are stored in the INTERVAL datatype.
Also, check: Oracle Create Index
Advantages of Oracle Datetime Datatype
The Datetime datatype in Oracle 21c has several advantages over other datatypes when it comes to working with date and time information in a database. Here are some of the main advantages:
- Storage efficiency: Compared to other datatypes like VARCHAR or CHAR, the Datetime datatype employs a smaller, more efficient binary format to store date and time information. For big databases in particular, this can save a lot of storage.
- High level of precision: If necessary, the Datetime datatype can hold date and time data with a level of precision down to fractions of a second. This makes it possible to accurately track and record events that take place relatively close together in time.
- Built-in functionality: The Datetime datatype includes built-in functions like TO CHAR, TO DATE, and DATEADD for manipulating and formatting date and time information. Without having to write complex SQL, these methods make it simple to do computations and conversions on date and time information.
- Time zone support: The Datetime datatype in Oracle 21c includes support for time zones, allowing for easy conversion between different time zones and accurate tracking of events that occur in different parts of the world.
- Indexing: The Datetime datatype can be indexed, which can significantly improve the performance of queries that involve date and time ranges. This is particularly useful for applications that need to retrieve data based on specific date and time criteria.
Syntax of Oracle Datetime Datatype
The syntax for creating a column with a datetime data type in Oracle is as follows:
column_name datatype [NULL | NOT NULL]
Example:
Here is an example of DateTime Datatype in Oracle 21c
CREATE TABLE orders (
order_id NUMBER PRIMARY KEY,
order_date DATE,
customer_name VARCHAR2(50),
total_amount NUMBER(10, 2)
);
We’re making a table called “orders” with four columns in this example. The table’s primary key is “order id,” a column with a datatype of NUMBER. The order’s date and time are stored in the second column, “order date,” which has a datatype of DATE.
The name of the customer who placed the order is kept in the third column, “customer name,” which has the datatype VARCHAR2(50). The total amount of the order is kept up to two decimal places in the fourth column, “total amount,” which has the datatype NUMBER(10, 2).
INSERT INTO orders (order_id, order_date, customer_name, total_amount)
VALUES (1, TO_DATE('2023-03-17 09:30:00', 'YYYY-MM-DD HH24:MI:SS'), 'John Doe', 100.50);
Here we inserted the values into the following given tables

Read: Oracle Varchar2 Datatype
Features of Oracle Datetime Datatype
The Datetime datatype in Oracle 21c has several features that make it a powerful tool for working with date and time information in a database. Here are some of the main features:
- Precision: The Datetime datatype has a high level of precision that can be used to record date and time information down to fractions of a second if necessary. This makes it possible to accurately track and record events that take place relatively close together in time.
- Range of values: The Datetime datatype can contain times between midnight and 23:59:59.999999 as well as dates between January 1, 4712 BC and December 31, 9999 AD.
- Support for time zones: The Datetime datatype contains support for time zones, making it possible to accurately track events that take place around the world and convert between different time zones with ease.
- Built-in functions: The Datetime datatype includes built-in methods like TO CHAR, TO DATE, and DATEADD for manipulating and formatting date and time information.
- Time intervals: The Datetime datatype allows for the storage and manipulation of time intervals, such as durations or time spans. This is useful for applications that need to track the length of time between two events.
- Indexing: The Datetime datatype can be indexed, which can significantly improve the performance of queries that involve date and time ranges. This is particularly useful for applications that need to retrieve data based on specific date and time criteria.
Disadvantages of Oracle Datetime Datatype
While the Datetime datatype in Oracle 21c has many advantages, there are also some potential disadvantages to consider:
- Storage needs: The Datetime datatype can nevertheless take up more space than is required for some applications, despite being more storage-efficient than some other datatypes. For instance, utilising a separate date datatype may be more effective if an application simply needs to record dates rather than times.
- Although the Datetime datatype provides great precision for storing date and time information, it still has limitations on the number of digits it can hold for fractions of a second. This might be a problem for programs that need incredibly accurate timing data.
- Complexity: Dealing with date and time data may be challenging, and the Datetime datatype is no different. There are numerous operators and built-in functions to learn.
- Compatibility issues: The Datetime datatype may not be compatible with all applications or versions of Oracle. This can create challenges when migrating data between different systems or when working with third-party tools.
Conclusion:
So, in this Oracle tutorial, we understood how to define and use the INTERVAL YEAR Datatype in Oracle Database. And we have also covered a few sample examples related to it.
Also, take a look at some more Oracle tutorials
- Oracle Binary_double Datatype
- Nchar Datatype in Oracle Database
- NVARCHAR2 Datatype in Oracle Database
I am Bijay having more than 15 years of experience in the Software Industry. During this time, I have worked on MariaDB and used it in a lot of projects. Most of our readers are from the United States, Canada, United Kingdom, Australia, New Zealand, etc.
Want to learn MariaDB? Check out all the articles and tutorials that I wrote on MariaDB. Also, I am a Microsoft MVP.