Oracle Fast Formulas - Chapter 29: Writing Conditional Logic in Oracle Fusion Fast Formulas

 

Chapter 29: Writing Conditional Logic in Oracle Fusion Fast Formulas


Conditional logic is a fundamental building block in any programming or formula language. In Oracle Fusion Fast Formulas, it allows you to make decisions based on input values, database items, or any calculated result.

This chapter covers how to use conditional logic using IF, ELSE, and ELSIF statements, as well as the DECODE function and nested conditions.


๐Ÿ”น Basic Conditional Syntax

plsql
IF condition THEN <statements> ELSE <statements> ENDIF

๐Ÿ“˜ Example:

plsql
IF GRADE = 'A' THEN BONUS = SALARY * 0.20 ELSE BONUS = SALARY * 0.10 ENDIF

๐Ÿ” Using ELSIF for Multiple Conditions

plsql
IF YEARS_OF_SERVICE > 10 THEN BONUS = SALARY * 0.20 ELSIF YEARS_OF_SERVICE > 5 THEN BONUS = SALARY * 0.15 ELSE BONUS = SALARY * 0.10 ENDIF

This structure is cleaner when evaluating multiple exclusive conditions.


๐Ÿ”ธ Using AND, OR, and NOT

You can combine multiple conditions using:

  • AND: both conditions must be true

  • OR: at least one must be true

  • NOT: negates a condition

๐Ÿงช Example:

plsql
IF YEARS_OF_SERVICE > 5 AND PERFORMANCE = 'Excellent' THEN BONUS = 1000 ENDIF

๐Ÿ”น Using DECODE for Simple Condition Handling

DECODE is useful for short, simple conditions, similar to switch-case logic.

plsql
BONUS = DECODE(PERFORMANCE, 'Excellent', 1000, 'Good', 500, 0)

It works like:

scss
DECODE(expression, value1, result1, value2, result2, default_result)

๐Ÿง  Best Practices for Conditional Logic

#Tip
1Use IF-ELSIF-ELSE for clarity when comparing multiple values
2Use DECODE for simpler, shorter condition trees
3Always close your conditions with ENDIF
4Keep logic modular to avoid confusion in large formulas
5Use indentation for better readability

๐Ÿ“ Example Formula with Conditional Logic

plsql
DEFAULT FOR YEARS_OF_SERVICE IS 0 DEFAULT FOR SALARY IS 0 DEFAULT FOR PERFORMANCE IS 'Average' IF PERFORMANCE = 'Excellent' AND YEARS_OF_SERVICE > 5 THEN BONUS = SALARY * 0.25 ELSIF PERFORMANCE = 'Good' THEN BONUS = SALARY * 0.15 ELSE BONUS = SALARY * 0.05 ENDIF RETURN_VALUE = BONUS

๐Ÿ“š Mini Quiz

1. What is the use of DECODE in Fast Formulas?
a) To call external APIs
b) To decode encrypted input
c) To evaluate simple conditions
d) To fetch DBIs

✅ Answer: c) To evaluate simple conditions

2. What keyword is used to close an IF statement?
a) END
b) ENDIF
c) CLOSE
d) EXIT

✅ Answer: b) ENDIF

No comments:

Post a Comment