Friday, January 11, 2013

LocalTimestamp function


In Oracle/PLSQL, the localtimestamp function returns the current date and time in the time zone of the current SQL session as set by the ALTER SESSION command. It returns a TIMESTAMP value.
A similar function to the localtimestamp function is the current_timestamp function. The difference between these two functions is that the localtimestamp function returns a TIMESTAMP value while the current_timestamp function returns a TIMESTAMP WITH TIME ZONE value.

Syntax

The syntax for the localtimestamp function is:
localtimestamp

Applies To

  • Oracle 11g, Oracle 10g, Oracle 9i, Oracle 8i

For Example

If the following ALTER SESSION command was issued:
ALTER SESSION SET TIME_ZONE = '-7:0';
And then the following SQL statement was executed:
select localtimestamp
from dual;
You might get the following result:
10-Sep-05 10.58.24 PM
You then modified the session time zone with the following ALTER SESSION command:
ALTER SESSION SET TIME_ZONE = '-2:0';
And then the following SQL statement was executed:
select localtimestamp
from dual;
You would now get the following result:
10-Sep-05 03.58.24 AM
The session time zone value has changed from -7:0 to -2:0, causing the localtimestamp function to return the current date and time as a value 5 hours ahead.