Operating on the Same Correlation Variable Referencing Variables That Have not Been Matched Yet

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::= 19-10 Oracle Complex Event Processing CQL Language Reference arith_expr::= on page 5-6, identifier::= on page 7-16 In Example 19–1 , the pattern_measures_clause is: MEASURES A.itemId as itemId This section describes: ■ Section 19.2.1, Functions Over Correlation Variables in the MEASURES Clause For more information, see: ■ Section 19.1.2, Referencing Singleton and Group Matches ■ Section 19.1.3, Referencing Aggregates ■ Section 19.4, DEFINE Clause ■ Section 1.1.11, Functions

19.2.1 Functions Over Correlation Variables in the MEASURES Clause

In the MEASURES clause, you may apply any single-row or aggregate function to the attributes of events that match a condition. Example 19–11 applies the last function over correlation variable Z.c1 in the MEASURES clause. Example 19–11 Using Functions Over Correlation Variables query id=tkpattern_q41[CDATA[ select T.firstW, T.lastZ from tkpattern_S11 MATCH_RECOGNIZE MEASURES A.c1 as firstW, lastZ.c1 as lastZ ALL MATCHES PATTERNA W+ X+ Y+ Z+ DEFINE W as W.c2 prevW.c2, X as X.c2 prevX.c2, Y as Y.c2 prevY.c2, Z as Z.c2 prevZ.c2 as T ]]query Note the following in the MEASURES clause in Example 19–11 : ■ A.c1 will export the value of c1 in the first and only the first event that the query processes because: – A is not specified in the DEFINE clause, therefor it is always true. – A has no pattern quantifiers, therefor it will match exactly once. ■ The built-in aggregate function last will export the value of c1 in the last event that matched Z at the time the PATTERN clause was satisfied. For more information, see: ■ Section 19.1.3, Referencing Aggregates ■ Section 19.1.3.5, Using count With , identifier., and identifier.attr ■ Section 19.1.3.6, Using first and last