Oracle9i OLAP Developer's Guide to the OLAP DML Release 2 (9.2) Part Number A95298-01 |
|
Working with Expressions, 6 of 11
A numeric expression evaluates to data with any of the numeric data types (that is, INTEGER
, SHORTINTEGER
, DECIMAL
, SHORTDECIMAL,
and
NUMBER
). The data in a numeric expression can be any combination of the following:
In addition, you can join any of these three-part expressions with the arithmetic operators for a more complex numeric expression. You use arithmetic operators in numeric expressions with numeric data, which returns a numeric result. You can also use some arithmetic operators in date expressions with a mix of date and numeric data, to retrieve either a date or numeric result.
The following table shows the OLAP DML arithmetic operators. When you use two or more operators in a numeric expression, the expression is evaluated according to standard rules of arithmetic. The column entitled Priority indicates the order in which that operator is evaluated. Operators of the same priority are evaluated from left to right.
Operator | Operation | Priority |
---|---|---|
|
Sign reversal |
1 |
|
Exponentiation |
2 |
|
Multiplication and division |
3 |
|
Addition and subtraction |
4 |
You can include any type of numeric data in the same numeric expression.
The data type of the result is determined according to the following rules.
Numbers are converted to different data types according to the following rules.
IF you . . . | THEN . . . |
---|---|
use a value with the |
the value is converted to its long counterpart before using it. Note: See "Boolean Expressions" for information about problems that can occur when you mix |
save the results of a calculation as a value with the |
NA is stored when the result is outside the range of a |
assign the value of a |
the value is rounded before storing or using it. Note: If the decimal value is outside the range of an integer (approximately plus or minus 2 billion), then an NA is stored. |
use a decimal value where a value with the |
the value is rounded before storing or using it. Note: If the decimal value is outside the range of an integer (approximately plus or minus 2 billion), then an NA is stored. |
assign the value of a decimal expression to a variable with the |
only the first 7 significant digits are stored. |
combine |
all values are converted to |
If these conversions are not what you want, then you can use the CONVERT
,
TO_CHAR
, TO_NCHAR
, TO_NUMBER
, or TO_DATE
functions to get different results.
When you use a dimension with a data type of TEXT
in a numeric expression, the dimension value is treated as a position (an integer) and is used numerically. The position number is based on the default status list, not on current status.
When you use dates in arithmetic expressions, the result can be numeric or it can be a date. The following table shows the legal operations for dates and the data type of the result.
All decimal data are converted to floating point format, both for storing and for calculations. In floating point format, a number is represented by means of a mantissa and an exponent. The mantissa and the exponent are stored as binary numbers. The mantissa is a binary fraction which, when multiplied by a number equal to 2 raised to the exponent, produces a number that equals or closely approximates the original decimal number.
Because there is not always an exact binary representation for a fractional decimal number, just as there is not an exact representation for the decimal value of 1/3, fractional parts of decimal numbers cannot always be represented exactly as binary fractions. Arithmetic operations on floating point numbers may result in further approximations, and the inaccuracy will gradually increase with the number of operations. In addition to the approximation factor, the available number of significant digits affects the exactness of the result.
For all of these reasons, a result computed by the TOTAL
, AVERAGE
, or other aggregation functions on a DECIMAL
or SHORTDECIMAL
variable may differ in the least significant digits from a result you compute by hand. Because the SHORTDECIMAL
data type provides a maximum of only seven significant digits, you will see more of these differences with SHORTDECIMAL
data. Therefore, you might want to use the NUMBER
data type when accuracy is more important than computational speed, such as variables that contain currency amounts.
Another result of the fact that some fractional decimal numbers cannot be exactly represented by binary fractions is that for such numbers, the DECIMAL
data type will offer a different and closer approximation than the SHORTDECIMAL
data type, because it has more significant digits. This can lead to problems when SHORTDECIMAL
and DECIMAL
data types are mixed in a comparison expression. See the topic "Boolean Expressions" for information on how to handle such comparisons.
You can control the following types of errors:
REPORT
or the =
command, values are reported or stored as they are calculated, so the division by zero halts the loop before it has gone through all the values.
If you want to suppress the divide-by-zero error, then you can change the value of the DIVIDEBYZERO
option to YES
. This means that the result of any division by zero is NA and no error occurs. This allows the calculation of the other values of a dimensioned expression to continue.
ROOTOFNEGATIVE
option to YES
.DECIMALOVERFLOW
option works in a similar manner to DIVIDEBYZERO
. It lets you control whether an error is generated when a calculation produces a decimal result larger than it can handle.
|
Copyright © 2001, 2002 Oracle Corporation. All Rights Reserved. |
|