Oracle LOCALTIMESTAMP() Function

Oracle LOCALTIMESTAMP() is a built-in function that returns the current date and time in the current session time zone as a TIMESTAMP data type.

Oracle LOCALTIMESTAMP() Syntax

Here’s the syntax for the Oracle LOCALTIMESTAMP() function:

LOCALTIMESTAMP

or

LOCALTIMESTAMP(precision)

Parameters

precision

Optional. Specifies the precision of the fractional seconds for the returned timestamp value. It must be a number between 0 and 9. You cannot pass a NULL value, or Oracle will give an error.

Return Value

The Oracle LOCALTIMESTAMP() function returns the current date and time value in the Gregorian format as a TIMESTAMP data type in the current session time zone.

Oracle LOCALTIMESTAMP() Examples

Here are some examples that demonstrate the usage of the Oracle LOCALTIMESTAMP() function.

Basic Usage

To get the current date and time, use the following statement:

ALTER SESSION SET NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SSXFF';
SELECT
    LOCALTIMESTAMP
FROM dual;

Output:

LOCALTIMESTAMP
________________________________
2023-02-11 15:59:44.135000000

Here, we use the ALTER SESSION statement to modify the date explicit format of the current session.

Fractional Seconds

The Oracle LOCALTIMESTAMP() function allows you to specify the precision of the fractional seconds:

SELECT
    LOCALTIMESTAMP(1)
FROM dual;

Output:

LOCALTIMESTAMP(1)
________________________________
2023-02-11 15:59:59.300000000

Conclusion

Oracle LOCALTIMESTAMP() is a built-in function that returns the current date and time in the current session time zone as a TIMESTAMP data type.