Using Arithmetic Operators in Expressions
Go Up to Understanding SQL Expressions
To calculate numeric values in expressions, InterBase recognizes four arithmetic operators listed in the following table:
Operator | Purpose | Precedence |
---|---|---|
|
Multiplication |
1 |
/ |
Division |
2 |
+ |
Addition |
3 |
– |
Subtraction |
4 |
Arithmetic operators are evaluated from left to right, except when ambiguities arise. In these cases, InterBase evaluates operations according to the precedence specified in the table (for example, multiplications are performed before divisions, and divisions are performed before subtractions).
Arithmetic operations are always calculated before comparison and logical operations. To change or force the order of evaluation, group operations in parentheses. InterBase calculates operations within parentheses first. If parentheses are nested, the equation in the innermost set is the first evaluated, and the outermost set is evaluated last. For more information about precedence and using parentheses for grouping, see Determining Precedence of Operators.
The following example illustrates a WHERE
clause search condition that uses an arithmetic operator to combine the values from two columns, then uses a comparison operator to determine if that value is greater than 10:
DECLARE RAINCITIES CURSOR FOR SELECT CITYNAME, COUNTRYNAME INTO :cityname, :countryname FROM CITIES WHERE JANUARY_RAIN + FEBRUARY_RAIN > 10;