DB2 Server for VSE & VM: Application Programming


Using Functions

There are two types of functions. Column functions apply the function to a group of values in a column and produce one result value. Scalar functions apply the function to one or more values in each row and produce a result value for each row.

Using Column Functions

The column functions are:

   AVG   MAX   MIN   SUM   COUNT

The argument of a column function is an expression containing a column name (optionally preceded by DISTINCT or ALL-- ALL is the default). The argument follows the function and must be enclosed in parentheses.

DISTINCT indicates that duplicate values are to be eliminated before the function is applied. The following example counts the number of different projects that satisfy the search condition:

   SELECT COUNT(DISTINCT PROJNO)

For a detailed discussion of each of the column functions, see the DB2 Server for VSE & VM SQL Reference manual.

Using Scalar Functions

The scalar functions are:

   CHAR     FLOAT        MINUTE    TIMESTAMP
   DATE     HEX          MONTH     TRANSLATE
   DAY      HOUR         SECOND    VALUE
   DAYS     INTEGER      STRIP     VARGRAPHIC
   DECIMAL  LENGTH       SUBSTR    YEAR
   DIGITS   MICROSECOND  TIME

You can use scalar functions wherever an expression can be used. The first or only argument of each scalar function is an expression. If the value of any expression is a null value, the result will be a null value as well, except for the VALUE function.

For a detailed discussion of each of the scalar functions, see the DB2 Server for VSE & VM SQL Reference manual.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]