Scalar functions

A scalar function can be used wherever an expression can be used. The restrictions on the use of aggregate functions do not apply to scalar functions, because a scalar function is applied to single set of parameter values rather than to sets of values. The argument of a scalar function can be a function. However, the restrictions that apply to the use of expressions and aggregate functions also apply when an expression or aggregate function is used within a scalar function. For example, the argument of a scalar function can be a aggregate function only if a aggregate function is allowed in the context in which the scalar function is used.

If the argument of a scalar function is a string from a column with a field procedure, the function applies to the decoded form of the value and the result of the function does not inherit the field procedure.

Example: The following SELECT statement calls for the employee number, last name, and age of each employee in department D11 in the sample table DSN8A10.EMP. To obtain the ages, the scalar function YEAR is applied to the expression:
   CURRENT DATE - BIRTHDATE
in each row of DSN8A10.EMP for which the employee represented is in department D11:
   SELECT EMPNO, LASTNAME, YEAR(CURRENT DATE - BIRTHDATE)
     FROM DSN8A10.EMP
     WHERE WORKDEPT = 'D11';