Oracle LOCALTIMESTAMP

The Oracle LOCALTIMESTAMP function returns a TIMESTAMP value that represents the current date and time in the session time.

Notice that the LOCALTIMESTAMP function returns a TIMESTAMP value while the CURRENT_TIMESTAMP function returns a TIMESTAMP WITH TIME ZONE value.

Syntax

The following illustrates the syntax of the Oracle LOCALTIMESTAMP function:

LOCALTIMESTAMP(fractional_second_precision)
Code language: SQL (Structured Query Language) (sql)

Arguments

The LOCALTIMESTAMP function accepts one optional argument:

1) fractional_second_precision

This argument specifies the fractional second precision for the returned time value.

Return Value

The Oracle LOCALTIMESTAMP function returns a TIMESTAMP value.

Examples

The following statement shows the returned values of the LOCALTIMESTAMP and CURRENT_TIMESTAMP:

SELECT
  LOCALTIMESTAMP, 
  CURRENT_TIMESTAMP
FROM
  dual;Code language: SQL (Structured Query Language) (sql)
Oracle LOCALTIMESTAMP function example

As you can see, the LOCATIMESTAMP function returned a time stamp without the session time zone data.

Let’s change the session time zone to the new one:

ALTER SESSION SET TIME_ZONE = '-9:00';Code language: SQL (Structured Query Language) (sql)

And execute the LOCALTIMESTAMP and CURRENT_TIMESTAMP functions again:

SELECT
  LOCALTIMESTAMP, 
  CURRENT_TIMESTAMP
FROM
  dual;Code language: SQL (Structured Query Language) (sql)
Oracle LOCALTIMESTAMP function

The output showed that both the returned time stamps were adjusted to the new session time zone.

In this tutorial, you have learned how to use the Oracle LOCATIMESTAMP function to get a TIMESTAMP value that represents the current time stamp in the session time zone.

Was this tutorial helpful?