ESQL functions

A function is an Start of changeESQL constructEnd of change that calculates a value from a number of given input values.

Start of changeA function usually has input parameters and can, but does not usually have, output parameters. It returns a value calculated by the algorithm described by its statement. This statement is usually a compound statement, such as BEGIN... END, because this allows an unlimited number of nested statements to be used to implement the algorithm.End of change

Start of changeESQL provides a number of predefined, or "built-in", functions which you can use freely within expressions. You can also use the CREATE FUNCTION statement to define your own functions.End of change

When you define a function, you must give it a unique name. The name is handled in a case insensitive way (that is, use of the name with any combination of upper and lower case letters matches the declaration). This is in contrast to the names that you declare for schemas, constants, variables, and labels, which are handled in a case sensitive way, and which you must specify exactly as you declared them.

Consider the following ESQL program fragment:

SET Diameter = SQRT(Area / 3.142) * 2;

In this example, the function SQRT (square root) is given the value inside the brackets (itself the result of an expression, a divide operation) and its result is used in a further expression, a multiply operation. Its return value is assigned to the variable Diameter. See Calling ESQL functions for information about all the Start of changebuilt-inEnd of change ESQL functions.

Start of changeIn addition, an ESQL expression can refer to a function in another broker schema (that is, a function defined by a CREATE FUNCTION statement in an ESQL file in the same or in a different dependent project). To resolve the name of the called function, you must do one of the following: End of change

Start of changeNote that you cannot define a function within an EVAL statement or an EVAL function.End of change

Related concepts
Message flows overview
Mappings
Related tasks
Developing message flows
Developing ESQL
Related reference
Built-in nodes
ESQL reference
Calling ESQL functions
CREATE FUNCTION statement
CREATE MODULE statement
CREATE PROCEDURE statement