PL/SQL SYSTIMESTAMP

The Oracle PL/SQL SYSTIMESTAMP function returns the system date and time including fractional seconds and time zone information. This function provides a precise time stamp for events, transactions, and data changes in the Oracle database.

Syntax

The syntax for the SYSTIMESTAMP function is as follows:

SYSTIMESTAMP [(precision)]

The optional precision parameter specifies the number of digits for the fractional seconds portion of the timestamp. The valid range for the precision parameter is 0 to 9, and the default value is 6.

Example

Here is an example of using the SYSTIMESTAMP function in a PL/SQL block:

DECLARE
current_ts TIMESTAMP := SYSTIMESTAMP;
BEGIN
DBMS_OUTPUT.PUT_LINE('Current timestamp is: ' || current_ts);
END;

This code declares a variable named current_ts of type TIMESTAMP and assigns it the value returned by the SYSTIMESTAMP function. The value of current_ts is then displayed using the DBMS_OUTPUT.PUT_LINE procedure.

The output of this code might look something like this:

Current timestamp is: 2023-04-09 12:34:56.123456789 +00:00

In this example, the SYSTIMESTAMP function returns a timestamp with a precision of 9 decimal places, which includes fractional seconds up to nanosecond resolution. The time zone information is also included, indicated by the +00:00 offset from UTC.

In summary, the Oracle PL/SQL SYSTIMESTAMP function is a powerful tool for capturing precise date and time information in the Oracle database. It can be used for a wide range of applications, including transaction auditing, event logging, and data synchronization.