Oracle PL/SQL provides a variety of built-in functions that help developers work with dates and timestamps. One such function is the CURRENT_TIMESTAMP function, which returns the current date and time in the session time zone.
The syntax of the CURRENT_TIMESTAMP function is simple:
This function does not take any arguments.
The function returns a value of the TIMESTAMP WITH TIME ZONE data type, which is a timestamp value that includes the time zone offset. The format of the timestamp value is ‘YYYY-MM-DD HH:MI:SS.FF TZH:TZM’, where TZH:TZM is the time zone offset in hours and minutes.
Example of how to use the CURRENT_TIMESTAMP function in a PL/SQL block:
DECLARE current_ts TIMESTAMP WITH TIME ZONE; BEGIN current_ts := CURRENT_TIMESTAMP; DBMS_OUTPUT.PUT_LINE('Current timestamp is ' || TO_CHAR(current_ts, 'YYYY-MM-DD HH:MI:SS.FF TZH:TZM')); END;
In this example, the CURRENT_TIMESTAMP function is called and the result is stored in the current_ts variable. The TO_CHAR function is then used to convert the timestamp value to a string in the desired format, which is printed to the console using the DBMS_OUTPUT.PUT_LINE procedure.
The CURRENT_TIMESTAMP function is a useful tool for working with timestamps in PL/SQL, especially when dealing with time-sensitive applications that require accurate and up-to-date timestamps.