Library /sys$common/syshlp/SQL$HELP_OLD72.HLB  —  Arithmetic Expressions
    An arithmetic expression is a value expression formed by
    combining one or more numeric value expressions with arithmetic
    operators. When you use an arithmetic expression in a statement,
    SQL calculates the numeric value associated with the expression
    and uses that value when executing the statement.

    You cannot use text values in arithmetic expressions whether they
    are literals, stored in parameters, or stored in table columns.

    If either operand of an arithmetic expression is a null value,
    the resulting value is also null.

    The arithmetic operators and their functions are:

    +       Addition
    -       Subtraction
    *       Multiplication
    /       Division

    You do not have to use spaces to separate arithmetic operators
    from value expressions.

    You can use parentheses to control the order in which SQL
    performs arithmetic operations. SQL follows the normal rules
    of precedence. That is, it evaluates arithmetic expressions in
    the following order:

    1. Value expressions in parentheses

    2. Multiplication and division, from left to right

    3. Addition and subtraction, from left to right

    You can use date-time variables and constants in arithmetic
    expressions.

    The following restrictions apply to date-time arithmetic:

    o  You cannot use the DATE VMS data type in date arithmetic; you
       must use the CAST function (CAST(VMS_COL AS TIMESTAMP(2))) or
       alter the DATE VMS domain to DATE ANSI or TIMESTAMP.

    o  You must use an interval qualifier with date-time data types
       in subtraction operations.

    o  Certain subtraction operations can produce an answer that can
       be either a YEAR-MONTH interval or a DAY-TIME interval. For
       example, when subtracting a timestamp from a timestamp or a
       timestamp from a date, you must specify the qualifier desired
       as follows:

       SQL> CREATE TABLE ORDER_TABLE
       cont> (PART_NUM INT,
       cont> ORDER_LOGGED TIMESTAMP(2),
       cont> DELIVERY_DATE TIMESTAMP(2),
       cont> TIME_TO_DELIVER COMPUTED BY (DELIVERY_DATE - ORDER_LOGGED) DAY(2)
       cont> TO MINUTE, SLOW_DELIVERY COMPUTED BY EXTRACT(DAY FROM
       cont> (DELIVERY_DATE - ORDER_LOGGED) DAY(2)) - 30);

    o  You cannot add days to or subtract days from TIME. The result
       exceeds the allowable range for TIME. The interval day-time
       column must be a subset of HOURS to SECOND.

    o  You cannot add hours to or subtract hours from DATE. The
       interval day-time column must be DAYS only.
Close Help