Functions Over Correlation Variables in the MEASURES Clause

19-14 Oracle Complex Event Processing CQL Language Reference On receiving a new tuple from the base stream, the conditions of the correlation variables that are relevant at that point in time are evaluated. A tuple is said to have matched a correlation variable if it satisfies its defining condition. A particular input can match zero, one, or more correlation variables. The relevant conditions to be evaluated on receiving an input are determined by logic governed by the PATTERN clause regular expression and the state in pattern recognition process that we have reached after processing the earlier inputs. The condition can refer to any of the attributes of the schema of the stream or view that evaluates to a stream on which the MATCH_RECOGNIZE clause is being applied. A correlation variable in the PATTERN clause need not be specified in the DEFINE clause: the default for such a correlation variable is a predicate that is always true. Such a correlation variable matches every event. It is an error to specify a correlation variable in the DEFINE clause which is not used in a PATTERN clause No correlation variable defined by a SUBSET clause may be defined in the DEFINE clause. pattern_definition_clause::= non_mt_corrname_definition_list::= on page 19-14 non_mt_corrname_definition_list::= correlation_name_definition::= on page 19-14 correlation_name_definition::= correlation_name::= on page 19-11, non_mt_cond_list::= on page 7-24 This section describes: ■ Section 19.4.1, Functions Over Correlation Variables in the DEFINE Clause ■ Section 19.4.2, Referencing Attributes in the DEFINE Clause ■ Section 19.4.3, Referencing One Correlation Variable From Another in the DEFINE Clause For more information, see: ■ Section 19.1.2, Referencing Singleton and Group Matches ■ Section 19.1.3, Referencing Aggregates ■ Section 19.1.3.6, Using first and last ■ Section 19.1.4, Using prev ■ Section 19.3, PATTERN Clause ■ Section 19.11, SUBSET Clause ■ Section 1.1.11, Functions Pattern Recognition With MATCH_RECOGNIZE 19-15

19.4.1 Functions Over Correlation Variables in the DEFINE Clause

You can use functions over the correlation variables while defining them. Example 19–12 applies the to_timestamp function to correlation variables. Example 19–12 Using Functions Over Correlation Variables: to_timestamp ... PATTERN A B C DEFINE A AS A.temp = 25, B AS B.temp = 25 and to_timestampB.element_time - to_timestampA.element_time INTERVAL 0 00:00:05.00 DAY TO SECOND, C AS to_timestampC.element_time - to_timestampA.element_time = INTERVAL 0 00:00:05.00 DAY TO SECOND ... Example 19–13 applies the count function to correlation variable B to count the number of times its definition was satisfied. A match is recognized when totalCountValue is less than 1000 two or more times in 30 minutes. Example 19–13 Using Functions Over Correlation Variables: count ... MATCH_RECOGNIZE ... PATTERNB DURATION 30 MINUTES DEFINE B as B.totalCountValue 1000 and countB. = 2 ... 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 ■ Section 19.1.4, Using prev

19.4.2 Referencing Attributes in the DEFINE Clause

You can refer to the attributes of a base stream: ■ Without a correlation variable: c1 20. ■ With a correlation variable: A.c1 20. When you refer to the attributes without a correlation variable, a tuple that last matched any of the correlation variables is consulted for evaluation. Consider the following definitions: ■ DEFINE A as c1 20 ■ DEFINE A as A.c1 20 Both refer to c1 in the same tuple which is the latest input tuple. This is because on receiving an input we evaluate the condition of a correlation variable assuming that the latest input matches that correlation variable. If you specify a correlation name that is not defined in the DEFINE clause, it is considered to be true for every input.