Using prev Understanding Pattern Recognition With MATCH_RECOGNIZE

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. Pattern Recognition With MATCH_RECOGNIZE 19-13

19.3.2 Grouping and Alternation in the PATTERN Clause

As shown in the regexp_grp_alt syntax, you can use: ■ open and close round brackets and to group correlation variables ■ alternation operators | to match either one correlation variable or group of correlation variables or another regexp_grp_alt::= correlation_name::= on page 19-11, pattern_quantifier::= on page 19-12, regexp::= on page 19-11 Consider the following pattern_clause: PATTERN A+ B+ This means A one or more times followed by B one or more times. You can group correlation variables. For example : PATTERN A+ C+ B+ This means A one or more times followed by zero or more occurrences of C one or more times and B one or more times. Using the PATTERN clause alternation operator |, you can refine the sense of the pattern_clause . For example: PATTERN A+ | B+ This means A one or more times or B one or more times, whichever comes first. Similarly, you can both group correlation variables and use the alternation operator. For example: PATTERN A+ C+ | B+ This means A one or more times followed by either C one or more times or B one or more times, whichever comes first. To match every permutation you can use: PATTERN A B | B A This means A followed by B or B followed by A, which ever comes first. For more information, see: ■ Section 19.3.1, Pattern Quantifiers and Regular Expressions ■ Alternation Operator on page 4-5

19.4 DEFINE Clause

The DEFINE clause specifies the boolean condition for each correlation variable. You may specify any logical or arithmetic expression and apply any single-row or aggregate function to the attributes of events that match a condition.