In this tutorial, we are going to break down one of the most simplistic yet convenient functions in Oracle databases.
Working with dates and date values in databases is nothing to take lightly. This is because you will often encounter the date values across all your data. Hence, having simple tools and helpers in your database is a heavy feature.
Oracle SYSDATE Function
The SYSDATE function in Oracle allows you to fetch the current date and time from the host system where the Oracle server is installed and running.
This is a very convenient function as it can allow you to quickly insert the timestamp information in a column, denoting when the changes to the row have occurred.
Function Syntax:
The SYSDATE function is effortless and does not require arguments.
The following shows the syntax for the sysdate function call:
As mentioned, the function returns the current date and time from the host system. The resulting value is the DATE data type with the specified format in the NLS_DATE_FORMAT parameter.
Function Usage Illustration:
Although the function is simple and easy to understand, let us provide some basic examples to demonstrate how the function works.
The provided query uses the to_char function to convert the current date into a long format. The result is as follows:
---------------
"Thursday, December 24, 2022"
If you do not want to use the long date format, you can use the format as shown in the following:
Output:
----------------------
2022-12-24 06:35:15
We can also perform a quick date arithmetic using the sysdate function and the given interval.
For example, to determine the time in the next 10 hours from now, we can run the following command:
Outcome:
-----------------
2022-11-24 16:42:12
Conclusion
This concise tutorial describes how to use the sysdate function in Oracle databases to fetch the current date and time from the host system.