Oracle® OLAP DML Reference 10g Release 2 (10.2) Part Number B14346-01 |
|
|
View PDF |
A conditional expression is an expression you can use to select one of two values based on a Boolean condition. A conditional expression contains the conditional operators IF
. . .THEN
. . .ELSE
and has the following format.
IF Boolean-expression THEN expression1 ELSE expression2
You can use a conditional expression as part of any other expression as long as the data type is appropriate.
Note: Do not confuse a conditional expression with theIF command, which has similar syntax but a different purpose. The IF command does not have a data type and is not evaluated like an expression. |
A conditional expression is processed by first evaluating the Boolean expression; then:
When the result of the Boolean expression is TRUE
, then expression1 is evaluated and returns that value.
When the result of the Boolean expression is FALSE
, then expression2 is evaluated and returns that value.
The expression1
and expression2
arguments are any valid OLAP DML expressions that evaluate to the same basic data type. However, when the data type of either value is DATE
, it is possible for the other value to have a numeric or text data type. Because both data types are expected to be DATE
, Oracle OLAP converts the numeric or text value to a DATE
. The data type of the whole expression is the same as the two expressions. When the result of the Boolean expression is NA
, then NA
is returned.
Example 2-2 Report with Conditional Expression
This example shows a sales bonus report. The bonus is 5 percent of the amount that sales exceeded budget, but when sales in the district are below budget, then the bonus is zero.
LIMIT month TO 'Jan02' TO 'Jun02' LIMIT product TO 'Tents' REPORT DOWN district IF sales-sales.plan LT 0 THEN 0 ELSE .05*(sales-sales.plan) PRODUCT: TENTS ---IF SALES-SALES.PLAN LT 0 THEN 0 ELSE .05*(SALES-SALES.PLAN)--- ----------------------MONTH------------------------------ DISTRICT Jan02 Feb02 Mar02 Apr02 May02 Jun02 --------- -------- -------- -------- ------- --------- ---------- Boston 229.53 0.00 0.00 0.00 584.51 749.13 Atlanta 0.00 0.00 0.00 190.34 837.62 1,154.87 Chicago 0.00 0.00 0.00 84.06 504.95 786.81 ...