Running Aggregates and Final Aggregates

19-8 Oracle Complex Event Processing CQL Language Reference ■ count means The number of all tuples, including duplicates and nulls. That is, the number of all tuples received on S, whether they satisfy the MATCH_ RECOGNIZE clause or not. ■ countA.balance means The number of all tuples that match the correlation variable A where the balance is not NULL. For more information, see: ■ count on page 9-5 ■ Section 1.1.3.1.1, Range, Rows, and Slide at Query Start-Up and for Empty Relations ■ Section 19.1.2, Referencing Singleton and Group Matches ■ Section 19.1.3, Referencing Aggregates ■ Section 19.1.3.3, Referencing Variables That Have not Been Matched Yet ■ Section 19.1.3.4, Referencing Attributes not Qualified by Correlation Variable

19.1.3.6 Using first and last

Use the first and last built-in aggregate functions to access event attributes of the first or last event match, respectively: first returns the value of the first match of a group in the order defined by the ORDER BY clause or the default order. last returns the value of the last match of a group in the order defined by the ORDER BY clause or the default order. The first and last functions accept an optional non-negative, constant integer argument N that indicates the offset following the first and the offset preceding the last match of the variable, respectively. If you specify this offset, the first function returns the N-th matching event following the first match and the last function returns the N-th matching event preceding the last match. If the offset does not fall within the match of the variable, the first and last functions return NULL. For more information, see: ■ first on page 9-7 ■ last on page 9-9 ■ Section 19.1.3, Referencing Aggregates ■ Section 19.6, ORDER BY Clause

19.1.4 Using prev

Use the prev built-in single-row function to access event attributes of a previous event match. If there is no previous event match, the prev function returns NULL. The prev function accepts an optional non-negative, constant integer argument N that indicates the offset to a previous match. If you specify this offset, the prev function returns the N-th matching event preceding the current match. If there is no such previous match, the prev functions returns NULL. When you use the prev function in the DEFINE clause, this function may only access the currently defined correlation variable. For example: the correlation variable definition in Example 19–9 is valid: Pattern Recognition With MATCH_RECOGNIZE 19-9 Example 19–9 Use of the prev Function: Valid Y AS Y.price prevY.price, 2 However, the correlation variable definition in Example 19–10 is invalid because while defining correlation variable Y, it references correlation variable X inside the prev function. Example 19–10 Use of the prev Function: Invalid Y AS Y.price prevX.price, 2 For more information, see: ■ prev on page 8-9 ■ Section 19.4, DEFINE Clause

19.2 MEASURES Clause

The MEASURES clause exports makes available for inclusion in the SELECT attribute values of events that successfully match the pattern you specify. You may specify expressions over correlation variables that reference partition attributes, order by attributes, singleton variables and aggregates on group variables, and aggregates on the attributes of the stream that is the source of the MATCH_ RECOGNIZE clause. You qualify attribute values by correlation variable to export the value of the attribute for the event that matches the correlation variable’s condition. For example, within the MEASURES clause, A.c1 refers to the value of event attribute c1: ■ In the tuple that last matched the condition corresponding to correlation variable A, if A is specified in the DEFINE clause. ■ In the last processed tuple, if A is not specified in the DEFINE clause. This is because if A is not specified in the DEFINE clause, then A is considered as TRUE always. So effectively all the tuples in the input match to A. You may include in the SELECT statement only attributes you specify in the MEASURES clause. pattern_measures_clause::= non_mt_measure_list::= on page 19-9 non_mt_measure_list::= measure_column::= on page 19-9 measure_column::=