.-ALL------. >>-COUNT--(----+-+----------+---expression--+--)--------------->< | '-DISTINCT-' | '-*--------------------------'
The schema is SYSIBM.
The COUNT function returns the number of rows or values in a set of rows or values.
If DISTINCT is used, the resulting data type of expression must not have a length greater than 255 for a character column or 127 for a graphic column. The data type of expression cannot be a LONG VARCHAR, LONG VARGRAPHIC, BLOB, CLOB, DBCLOB, DATALINK, distinct type on any of these types, or structured type (SQLSTATE 42907).
The result of the function is a large integer. The result cannot be null.
The argument of COUNT(*) is a set of rows. The result is the number of rows in the set. A row that includes only NULL values is included in the count.
The argument of COUNT(DISTINCT expression) is a set of values. The function is applied to the set of values derived from the argument values by the elimination of null and duplicate values. The result is the number of different non-null values in the set.
The argument of COUNT(expression) or COUNT(ALL expression) is a set of values. The function is applied to the set of values derived from the argument values by the elimination of null values. The result is the number of non-null values in the set, including duplicates.
Examples:
SELECT COUNT(*) INTO :FEMALE FROM EMPLOYEE WHERE SEX = 'F'
Results in FEMALE being set to 13 when using the sample table.
SELECT COUNT(DISTINCT WORKDEPT) INTO :FEMALE_IN_DEPT FROM EMPLOYEE WHERE SEX = 'F'
Results in FEMALE_IN_DEPT being set to 5 when using the sample table. (There is at least one female in departments A00, C01, D11, D21, and E11.)