|Oracle® OLAP DML Reference
11g Release 1 (11.1)
|PDF · Mobi · ePub|
Within an OLAP DML program, the IF...THEN...ELSE command executes one or more statements in a program when a specified condition is met. Optionally, it also executes an alternative statement or group of statements when the condition is not met.
Note:You can also use IF as a conditional operator in an expression. See "IF...THEN...ELSE expression"
Any valid Boolean expression that returns either
Oracle OLAP executes the statement1 argument when the Boolean expression is
TRUE. The statement1 must be on the same line as THEN.
Oracle OLAP executes the statement2 argument when the Boolean expression is
FALSE. The statement2 must be on the same line as ELSE. When you omit the ELSE phrase, execution continues with the statement after the whole IF...THEN... statement in the program.
You can use an IF statement for conditional execution of two or more statements by following the THEN or ELSE (or both) keywords with a DO ... DOEND sequence. See Example 10-5, "Using IF...THEN...ELSE".
When IF is used as an expression, the THEN and ELSE keywords must be on the same line as IF. When IF is used as a command, THEN and ELSE must be on separate lines.
The following lines from a program illustrate the use of IF...THEN...ELSE.... When the Boolean expression
ANY(DOLLARS LT 200000) is
TRUE, the statements following THEN (
statement group 1) are executed. When the expression is
FALSE, the statements following ELSE (
statement group 2) are executed instead.
IF ANY(DOLLARS LT 200000) THEN DO ... " (statement group 1) DOEND ELSE DO ... "(statement group 2) DOEND
In a program that produces a report, you would like to report a previous year's actual expenses or the current year's budget, depending on the year passed to the program as an argument. A conditional expression in a JOINCHARS function produces a heading with the word Actual or Budget. Another conditional expression selects the variable to report. The program would include the following lines.
ARGUMENT cur.year year LIMIT month TO year cur.year REPORT - HEADING JOINCHARS( 'Expenses: ' - IF cur.year LT 'Yr95' - THEN 'Actual FOR ' - ELSE 'Budget FOR ', - cur.year ) - IF cur.year LT 'Yr95' THEN actual ELSE budget