Ask Reuben – September 15, 2025
Operator vs Function
Why can’t I apply string methods directly to SFMT or LSTR?
Within a computer language, the code is made up of different parts. If we look at the language basics, these include concepts like data types, literals, variables. The two I want to look at for this article are operators and functions, because there are some operators that look like functions.
If we look at the operator documentation, we see that operators are basic syntax elements that appear in expressions. There are different kinds of operators …
- Basic operators such as
+
,||
,AND
,ASCII
, which take a left operand, a right operand, or both left and right operands. When used together in the same expression, basic operators follow the order of precedence list.- Assignment operators such as
+=
,||=
, are part of the syntax of theLET
statement, and can only be used withing this statement. Consequently, assignment operators are not concerned by precedence order rules.- Function operators like
TODAY
,IIF()
,SFMT()
, where some take parameters enclosed in parentheses. Function operators act like functions by returning a value. Function operators have the lowest order of precedence when used with basic operators. Function operators can be identified with the [function] marker in the title of their reference topic.- Variable operators like
SQLSTATE
, with the same predecence rules than function operators. Variable operators can be identified with the [variable] marker in the title of their reference topic.
… the third entry listed above is Function operators, these operators may
- look like functions because they might take some parameters specified in parentheses
- and act like functions in that they return a value
For most operators, the value they return depends upon the passed in parameters. For instance NVL() will return the datatypes that are passed in, and the same is true of IIF(). There is no expectation that you can invoke methods like you can with an object reference e.g. IIF(boolean-expr, expr-if-true, expr-otherwise).toUpperCase()
because there is no guarantee that what IIF returns will be a STRING. If expr-if-true is an INTEGER, an INTEGER maybe returned.
The two operators SFMT and LSTR do cause some confusion in this area because although they are operators, they do take parameters inside parentheses, they do return a value, and that returned value will most likely be a STRING. Sometimes developers get caught out trying to invoke methods directly off SFMT and LSTR e.g. LSTR("token"||idx).toUpperCase()
, SFMT("%1(%2)", var1, var2).toLowerCase()
.
You can always create your own functions that wrap the operator to save a line of code, however to me that seems a bit of overkill.
What I will point out is that using Genero Studio Code Editor, SFMT, LSTR are recognised as operators and will appear as the same color as other operators which is a different color than functions and methods.