Oracle Fast Formulas - Chapter 6: Fast Formula Syntax and Writing Best Practices

 Oracle Fast Formulas - Chapter 6: Fast Formula Syntax and Writing Best Practices


Objective of This Chapter

This chapter teaches you how to write clean, efficient, and error-free Fast Formulas.
Good syntax and best practices are critical for formula performance and maintainability.


Basic Syntax Rules

  1. Formula Structure:
    Fast Formulas have four main sections:

    • Inputs

    • Default Values

    • Formula Logic

    • Outputs

  2. Comments:
    Use /* comment */ to add notes for understanding the logic.
    Example:

    /* This formula calculates bonus */
  3. Input Variables:
    Always declare inputs at the start.
    Example:

    INPUTS ARE salary, bonus
  4. Default Values:
    Set default values to avoid NULL errors.
    Example:

    DEFAULT FOR salary IS 0
  5. Assignment Operator:
    Use = to assign values.
    Example:

    total_salary = salary + bonus
  6. Conditional Logic:
    Use IF THEN ELSE blocks. Example:

    IF salary > 50000 THEN bonus = 5000 ELSE bonus = 2000
  7. Return Output:
    Output values using RETURN keyword. Example:

    RETURN total_salary

Writing Best Practices

  1. Use Meaningful Names
    Always use understandable variable names like monthly_bonus instead of mb.

  2. Indent Code Properly
    Make your logic easy to read with proper indentation.

  3. Group Similar Logic Together
    Keep salary-related calculations together, absence-related together, etc.

  4. Avoid Hardcoding Values
    Always use inputs or lookup values instead of hardcoding inside formula.

  5. Use Default Values Smartly
    Never assume an input will always have a value. Default them.

  6. Minimize IF ELSE Chains
    Use nested conditions wisely to keep the formula efficient.

  7. Keep Formula Short and Simple
    Break down complex formulas into smaller ones if needed.

  8. Validate Formula Step-by-Step
    Test small parts first, then the whole formula.

  9. Always Handle NULL Cases
    Write fallback conditions wherever required.

  10. Use Effective Commenting
    Every critical logic must have a short comment.


Sample Template for Any Fast Formula


/* Purpose of the Formula: Bonus Calculation */ INPUTS ARE salary, performance_rating DEFAULT FOR salary IS 0 performance_rating IS 'AVERAGE' IF performance_rating = 'EXCELLENT' THEN bonus = salary * 0.2 ELSE bonus = salary * 0.1 RETURN bonus

Common Mistakes to Avoid

MistakeImpact
Not setting default valuesNULL errors during processing
Using hardcoded numbersDifficult to maintain
Long nested IF ELSE without commentsConfusing and error-prone
No fallback for unexpected inputsIncorrect outputs
Mixing business logic randomlyHard to debug

Mini Practice Quiz

  1. What symbol is used to write comments in Fast Formula
    A //
    B /* */
    C ##

Answer: B /* */

  1. If salary is NULL and no default is set, what happens
    A Formula runs normally
    B Formula gives NULL error
    C System auto fixes

Answer: B Formula gives NULL error

  1. What is the correct assignment operator in Fast Formula
    A :=
    B ==
    C =

Answer: C =


No comments:

Post a Comment