Function TABLE Query Queries

18-16 Oracle Complex Event Processing CQL Language Reference rules query id=SummarizeResultsRule[CDATA[ select crossRate1 || crossRate2 as crossRatePair, count as totalCount, :1 as averageInternalPrice from CrossRateStream group by crossRate1,crossRate2 having :2 ]]query rules bindings binding id=SummarizeResultsRule params id=avgcountavginternalPrice, count 0params binding bindings processor n1:config In this example, the: ■ MarketRule query specifies two parameters: the third term in the SELECT and the value of symbol in the WHERE clause ■ SummarizeResultsRule query specifies two parameters: the third term in the SELECT and the value of the HAVING clause. This section describes: ■ Section 18.2.11.1, Parameterized Queries in Oracle CQL Statements ■ Section 18.2.11.2, The bindings Element ■ Section 18.2.11.3, Run-Time Query Naming ■ Section 18.2.11.4, Lexical Conventions for Parameter Values ■ Section 18.2.11.5, Parameterized Queries at Runtime ■ Section 18.2.11.6, Replacing Parameters Programmatically

18.2.11.1 Parameterized Queries in Oracle CQL Statements

You may specify a placeholder anywhere an arithmetic expresion or a String literal is legal in an Oracle CQL statement. For example: ■ SELECT list items ■ WHERE clause predicates ■ WINDOW constructs such as RANGE, SLIDE, ROWS, and PARTITION BY ■ PATTERN duration clause For more information, see: ■ arith_expr on page 5-6 ■ Literals on page 2-8

18.2.11.2 The bindings Element

Parameter values are contained by a bindings element. There may be one bindings element per processor element. For each parameterized query, the bindings element must contain a binding element with the same id as the query. Oracle CQL Queries, Views, and Joins 18-17 The binding element must contain one or more params elements. Each params element must have a unique id and must contain a comma separated list of parameter values equal in number to the number of placeholder characters :n in the corresponding query. The order of the parameter values corresponds to placeholder characters :n in the parameterized query, such that :1 corresponds to the first parameter value, :2 corresponds to the second parameter value, and so on. You may use placeholder characters :n in any order. That is, :1 corresponds to the first parameter value whether it precedes or follows :2 in a query. A placeholder number can be used only once in a query. For more information, see: ■ Section 18.2.11.4, Lexical Conventions for Parameter Values ■ Section 18.2.11.5, Parameterized Queries at Runtime

18.2.11.3 Run-Time Query Naming

When a binding instantiates a parameterized query, Oracle CEP creates a new query at run time with the name queryId_paramId. For example, in Example 18–11 , the run-time name of the first query instantiated by the MarketRule binding is MarketRule_nasORCL. To avoid run-time naming conflicts, be sure query ID and parameter ID combinations are unique.

18.2.11.4 Lexical Conventions for Parameter Values

Each params element must have a unique id and must contain a comma separated list of parameter values equal in number to the number of placeholder characters :n in the corresponding query. In an Oracle CQL query, a placeholder within single or double quotes is a String literal. The following query is not a parameterized query: SELECT :1 as symbol, price FROM StockTick [RANGE 5 SECONDS] Oracle CEP parses this query as assigning the String literal :1 to alias symbol. To make this query into a parameterized query, use: SELECT :1 as symbol, price FROM StockTick [RANGE :2 SECONDS] And define a params element like this: params id=p1ORCL, 5params Table 18–2 Parameterized Query Parameter Value Lexical Conventions Convention Example Replacement Value Primitive type literals params id=p1NASDAQ, 200.0params :1 = NASDAQ :2 = 200.0 Oracle CQL fragments params id=p1count, avgvalparams :1 = count :2 = avgval Quotes params id=p1’alert’, Seattle, WA, ’fun’ || house, one two 3params :1 = ’alert’ :2 = Seattle, WA :3 = ’fun’ || house :4 = one two 3