Examples Of Interval Value Expressions - HP Neoview SQL Reference Manual

Hide thumbs Also See for Neoview SQL:
Table of Contents

Advertisement

Operands
Timestamp + Numeric or Numeric + Timestamp
Timestamp - Numeric
Timestamp – Interval
year-month Interval + year-month Interval
day-time Interval + day-time Interval
year-month Interval – year-month Interval
day-time Interval – day-time Interval
Time – Time
Timestamp – Timestamp
Interval * Number or Number * Interval
Interval / Number
Interval – Interval or Interval + Interval
When using these operations, note:
If you subtract a datetime value from another datetime value, both values must have the
same data type. To get this result, use the CAST expression. For example:
CAST (ship_timestamp AS DATE) - start_date
If you subtract a datetime value from another datetime value, and you specify the interval
qualifier, you must allow for the maximum number of digits in the result for the precision.
For example:
(CURRENT_TIMESTAMP - ship_timestamp) DAY(4) TO SECOND(6)
If you are updating a value that is the result of adding or subtracting two interval values,
an SQL error occurs if the source value does not fit into the target column's range of interval
fields. For example, this expression cannot replace an INTERVAL DAY column:
INTERVAL '1' MONTH + INTERVAL '7' DAY
If you multiply or divide an interval value by a numeric value expression, Neoview SQL
converts the interval value to its least significant subfield and then multiplies or divides it
by the numeric value expression. The result has the same fields as the interval that was
multiplied or divided. For example, this expression returns the value 5-02:
INTERVAL '2-7' YEAR TO MONTH * 2

Examples of Interval Value Expressions

The PROJECT table consists of six columns using 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,9657,'SALT LAKE CITY',DATE '1996-04-10',
TIMESTAMP '1996-04-21:08:15:00.00',INTERVAL '15' DAY);
The next example uses these values in the PROJECT table:
PROJCODE
1000
2000
2500
3000
START_DATE
1996-04-10
1996-06-10
1996-10-10
1996-08-21
Result type
Timestamp
Timestamp
Timestamp
year-month Interval
day-time Interval
year-month Interval
day-time Interval
Interval
Interval
Interval
Interval
Interval
SHIP_TIMESTAMP
1996-04-21:08:15:00.0000
1996-07-21:08:30:00.0000
1996-12-21:09:00:00.0000
1996-10-21:08:10:00.0000
EST_COMPLETE
15
30
60
60
Expressions
215

Advertisement

Table of Contents
loading

Table of Contents