09.01.2015 Views

PL/SQL User's Guide and Reference

PL/SQL User's Guide and Reference

PL/SQL User's Guide and Reference

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Predefined Datatypes<br />

Time (UTC)—formerly Greenwich Mean Time. You can also use named time zones,<br />

as with TIMESTAMP WITH TIME ZONE.<br />

The syntax is<br />

TIMESTAMP[(precision)] WITH LOCAL TIME ZONE<br />

where the optional parameter precision specifies the number of digits in the<br />

fractional part of the seconds field. You cannot use a symbolic constant or variable<br />

to specify the precision; you must use an integer literal in the range 0 .. 9. The<br />

default is 6.<br />

This datatype differs from TIMESTAMP WITH TIME ZONE in that when you insert a<br />

value into a database column, the value is normalized to the database time zone,<br />

<strong>and</strong> the time-zone displacement is not stored in the column. When you retrieve the<br />

value, Oracle returns it in your local session time zone.<br />

In the following example, you declare a variable of type TIMESTAMP WITH LOCAL<br />

TIME ZONE:<br />

DECLARE<br />

logoff TIMESTAMP(3) WITH LOCAL TIME ZONE;<br />

BEGIN<br />

...<br />

END;<br />

You cannot assign literal values to a variable of this type.<br />

INTERVAL YEAR TO MONTH<br />

You use the datatype INTERVAL YEAR TO MONTH to store <strong>and</strong> manipulate intervals<br />

of years <strong>and</strong> months. The syntax is:<br />

INTERVAL YEAR[(precision)] TO MONTH<br />

where precision specifies the number of digits in the years field. You cannot use<br />

a symbolic constant or variable to specify the precision; you must use an integer<br />

literal in the range 0 .. 4. The default is 2.<br />

In the following example, you declare a variable of type INTERVAL YEAR TO<br />

MONTH, then assign a value of 101 years <strong>and</strong> 3 months to it:<br />

DECLARE<br />

lifetime INTERVAL YEAR(3) TO MONTH;<br />

BEGIN<br />

lifetime := INTERVAL ’101-3’ YEAR TO MONTH; -- interval literal<br />

lifetime := ’101-3’; -- implicit conversion from character type<br />

<strong>PL</strong>/<strong>SQL</strong> Datatypes 3-19

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!