Referencing Attributes not Qualified by Correlation Variable Using count With , identifier., and identifier.attr

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 Pattern Recognition With MATCH_RECOGNIZE 19-11 ■ Section 19.1.4, Using prev

19.3 PATTERN Clause

The PATTERN clause specifies the pattern to be matched as a regular expression over one ore more correlation variables. Incoming events must match these conditions in the order given from left to right. The regular expression may contain correlation variables that are: ■ Defined in the DEFINE clause : such correlation variables are considered true only if their condition definition evaluates to TRUE. See Section 19.4, DEFINE Clause . ■ Not defined in the DEFINE clause: such correlation variables are considered as always TRUE; that is, they match every input. pattern_clause::= regexp::= on page 19-11, within_clause::= on page 19-21 This section describes: ■ Section 19.3.1, Pattern Quantifiers and Regular Expressions ■ Section 19.3.2, Grouping and Alternation in the PATTERN Clause For more information, see: ■ Section 19.12.1, Pattern Detection ■ Section 19.12.2, Pattern Detection With PARTITION BY ■ Section 19.12.3, Pattern Detection With Aggregates

19.3.1 Pattern Quantifiers and Regular Expressions

You express the pattern as a regular expression composed of correlation variables and pattern quantifiers. regexp::= correlation_name::= on page 19-11, pattern_quantifier::= on page 19-12 correlation_name::= const_string::= on page 7-12 19-12 Oracle Complex Event Processing CQL Language Reference pattern_quantifier::= Table 19–2 lists the pattern quantifiers pattern_quantifier::= on page 19-12 Oracle CQL supports. Use the pattern quantifiers to specify the pattern as a regular expression, such as A or A+?. The one-character pattern quantifiers are maximal or greedy; they will attempt to match as many instances of the regular expression on which they are applied as possible. The two-character pattern quantifiers are minimal or reluctant; they will attempt to match as few instances of the regular expression on which they are applied as possible. Consider the following pattern_clause: PATTERN A B C This pattern clause means a pattern match will be recognized when the following conditions are met by consecutive incoming input tuples: 1. Exactly one tuple matches the condition that defines correlation variable A, followed by 2. Zero or more tuples that match the correlation variable B, followed by 3. Exactly one tuple that matches correlation variable C. While in state 2, if a tuple arrives that matches both the correlation variables B and C since it satisfies the defining conditions of both of them then as the quantifier for B is greedy that tuple will be considered to have matched B instead of C. Thus due to the greedy property B gets preference over C and we match a greater number of B. Had the pattern expression be A B? C, one that uses a lazy or reluctant quantifier over B, then a tuple matching both B and C will be treated as matching C only. Thus C would get preference over B and we will match fewer B. For more information, see: ■ Section 19.1.2, Referencing Singleton and Group Matches ■ Section 19.3.2, Grouping and Alternation in the PATTERN Clause Table 19–2 MATCH_RECOGNIZE Pattern Quantifiers Maximal Minimal Description ? 0 or more times + +? 1 or more times. ? ?? 0 or 1 time. None None An unquantified pattern, such as A, is assumed to have a quantifier that requires exactly 1 match.