Considerations For Datetime Value Expressions; Examples Of Datetime Value Expressions - HP Neoview SQL Reference Manual

Hide thumbs Also See for Neoview SQL:
Table of Contents

Advertisement

Considerations for Datetime Value Expressions

Data Type of Result
In general, the data type of the result is the data type of the datetime-primary part of the
datetime expression. For example, datetime value expressions include:
CURRENT_DATE + INTERVAL '1' DAY
CURRENT_DATE + est_complete
( SELECT ship_timestamp FROM project WHERE
projcode=1000 ) + INTERVAL '07:04' DAY TO
HOUR
The datetime primary in the first expression is CURRENT_DATE, a function that returns a value
with DATE data type. Therefore, the data type of the result is DATE.
In the last expression, the datetime primary is this scalar subquery:
( SELECT ship_timestamp FROM project WHERE projcode=1000 )
The preceding subquery returns a value with TIMESTAMP data type. Therefore, the data type
of the result is TIMESTAMP.
Restrictions on Operations With Datetime or Interval Operands
You can use datetime and interval operands with arithmetic operators in a datetime value
expression only in these combinations:
Operand 1
Datetime
Interval
When a numeric value is added to or subtracted from a datetime type, the numeric value is
automatically CASTed to an INTERVAL DAY value. When a numeric value is added to or
subtracted from a time type or a timestamp type, the numeric value is automatically CASTed to
an INTERVAL SECOND value. For information on CAST, see
When using these operations, note:
Adding or subtracting an interval of months to a DATE value results in a value of the same
day plus or minus the specified number of months. Because different months have different
lengths, this is an approximate result.
Datetime and interval arithmetic can yield unexpected results, depending on how the fields
are used. For example, execution of this expression (evaluated left to right) returns an error:
DATE '1996-01-30' + INTERVAL '1' MONTH + INTERVAL '7' DAY
In contrast, this expression (which adds the same values as the previous expression, but in
a different order) correctly generates the value 1996-03-06:
DATE '1996-01-30' + INTERVAL '7' DAY + INTERVAL '1' MONTH
You can avoid these unexpected results by using the

Examples of Datetime Value Expressions

The PROJECT table consists of five columns that use the data types NUMERIC, VARCHAR,
DATE, TIMESTAMP, and INTERVAL DAY. Suppose that you have inserted values into the
PROJECT table. For example:
INSERT INTO persnl.project
VALUES (1000,'SALT LAKE CITY',DATE '1996-04-10',
TIMESTAMP '1996-04-21:08:15:00.00',INTERVAL '15' DAY);
Operator
+ or –
+
The sum of the current date and an interval value of one
day.
The sum of the current date and the interval value in
column EST_COMPLETE.
The sum of the ship timestamp for the specified project
and an interval value of seven days, four hours.
Operand 2
Interval
Datetime
"CAST Expression" (page
"ADD_MONTHS Function" (page
Result Type
Datetime
Datetime
298).
288).
Expressions
211

Advertisement

Table of Contents
loading

Table of Contents