7-12. Associating a Time Zone with a Date and Time

Problem

You want to associate a time zone with a given date and time in order to be more precise.

Solution

Create a code block that declares a field as type TIMESTAMP WITH TIME ZONE. Assign a TIMESTAMP to the newly declared field within the body of the code block. After doing so, the field that you declared will contain the date and time of the TIMESTAMP that you assigned along with the associated time zone. The following example demonstrates a code block that performs this technique using the SYSTIMESTAMP:

DECLARE   time   TIMESTAMP WITH TIME ZONE;  BEGIN   time := SYSTIMESTAMP;   DBMS_OUTPUT.PUT_LINE(time);  END;

The results that will be displayed via the call to DBMS_OUTPUT should resemble ...

Get Oracle and PL/SQL Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.