Use variables in rules

Variables can be used in rules as conditions and as conclusions. For example, you might want to prove the person's age (a number) from a person's date of birth (a date) and perhaps use this attribute as a condition determining whether the person is over the age of 18 (a boolean).

What do you want to do?

Specify the value for a variable in a rule

Use a variable in a condition

Use a variable in a mathematical calculation in a rule conclusion

Use a variable in a straight calculation in a rule calculation

Specify the value for a variable in a rule

To avoid ambiguity, the Oracle Policy Modeling compiler enforces strict formatting on the values of variables where the value is explicitly used in a rule. For the formatting requirements and other considerations when setting the value of a variable in a rule, see Use constant values in rules.

Use a variable in a condition

Like boolean attributes, variables can be used as conditions in any rule proving another attribute. When using variables in conditions you must state the value, or range of acceptable values, that are sufficient to satisfy the condition. To do this, you must use one of the standard logical operators. The value of the attribute may either be compared to a fixed value ("= 18") or to the value of another attribute ("= the spouse's date of birth").

NOTE: Where two variable attributes are being compared, they must be of the same variable type. When comparing a variable attribute with a constant value, the value must be in the specified format for that type of variable attribute. See Use constant values in rules for more information.


Operator Example
Greater than (>)

the person is over 18 if

the person's age > 18

Less than (<)

the employee is early for work if

the time the employee starts work < the specified start time for the employee

Equals (=)

the person was born on the same day as the person's spouse if

the person's date of birth = the person's spouse's date of birth

Not equal to (<>)

the pet is not a monkey if

the type of pet <> "monkey"

Greater than or equal to (>=)

the applicant is eligible for a loan if

the applicant's annual income >= 50000

Less than or equal to (<=)

the submission is valid if

the submission's date and time <= the latest submission date and time

Use a variable in a mathematical calculation in a rule conclusion

It is possible to perform a variety of mathematical calculations using variables. These operations include:

For the full list of supported operators and functions, see Numerical functions in the function reference.

For example,

the cost of the school lunch = the cost of the meat pie + the cost of the bag of the chips + the cost of the soft drink - the amount of the student discount

the person's share of household income = (the person's income + the partner's income)/2

TIP: Whilst the standard mathematical preference is applied to operators in the absence of parentheses (ie division, multiplication, addition, subtraction), you should make the order explicit with the use of parentheses.

Use a variable in a straight calculation in a rule conclusion

In the same way that a boolean attribute is set to a value when used in a rule conclusion, a variable can be assigned a value in a conclusion. For example, for the variable "the passenger’s allowance in Australian dollars" we can write the following rule:

the passenger's allowance in Australian dollars = 350

In this case, no conditions are required so the value is always inferred. Therefore, no alternative conclusion is produced.


See also