Detecting Differences in Query Results

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 18-18 Oracle Complex Event Processing CQL Language Reference Because the parameter value ORCL does not contain a comma, the quotes are not required. You could specify a params element like this: params id=p1ORCL, 5params However, if the parameter value does contain a comma, then you must use quotes around the parameter value. Consider this parameterized query: SELECT :1 = cityAndState AS cityOfInterest FROM channel1 [RANGE :2 SECONDS] Where cityAndState has values like Seattle, WA or Ottawa, ON. In this case, you must specify a params element like this: params id=p1Seattle, WA, 5params params id=p1Ottawa, ON, 5params Commas are allowed only in quoted parameter values that signify string values. Commas are not allowed as a separator character in unquoted parameter values. For example: Seattle, WA is valid, because the comma is part of the string. PARTITION BY fromRate,toRate ROWS 10 is invalid. Create the following two parameters instead: PARTITION BY fromRate ROWS 10 PARTITION BY toRate ROWS 10

18.2.11.5 Parameterized Queries at Runtime

Each params element effectively causes a new Oracle CQL query to execute with the new parameters. At rule execution time, Oracle CQL substitutes parameter values for placeholder characters, from left to right. Example 18–11 is effectively equivalent to the queries that Example 18–12 shows. Example 18–12 Equivalent Queries at Runtime SELECT symbol, AVGprice AS average, NASDAQ AS market FROM StockTick [RANGE 5 SECONDS] WHERE symbol = ORCL SELECT symbol, AVGprice AS average, NYSE AS market FROM StockTick [RANGE 5 SECONDS] WHERE symbol = JPM SELECT symbol, AVGprice AS average, NYSE AS market FROM StockTick [RANGE 5 SECONDS] WHERE symbol = WFC

18.2.11.6 Replacing Parameters Programmatically

If you use the CQLProcessorMBean.replaceAllBoundParameters method to programmatically replace parameters in a parameterized query, any existing parameters not replaced by the method are automatically removed from the query.

18.3 Views

Queries are the principle means of extracting information from data streams and relations. A view represents an alternative selection on a stream or relation that you can use to create subqueries. Oracle CQL Queries, Views, and Joins 18-19 A view is only accessible by the queries that reside in the same processor and cannot be exposed beyond that boundary. You can specify any query type in the definition of your view. For more information, see Section 18.2, Queries . For complete details on the view statement, see View on page 20-25. In Example 18–13 , query BBAQuery selects from view MAXBIDMINASK which in turn selects from other views such as BIDMAX which in turn selects from other views. Finally, views such as lastEvents select from an actual event source: filteredStream. Each such view represents a separate derived stream drawn from one or more base streams. Example 18–13 Using Views Instead of Subqueries view id=lastEvents schema=cusip bid srcId bidQty ask askQty seq[CDATA[ select cusip, bid, srcId, bidQty, ask, askQty, seq from filteredStream[partition by srcId, cusip rows 1] ]]view view id=bidask schema=cusip bid ask[CDATA[ select cusip, maxbid, minask from lastEvents group by cusip ]]view view id=bid schema=cusip bid seq[CDATA[ select ba.cusip as cusip, ba.bid as bid, e.seq from bidask as ba, lastEvents as e WHERE e.cusip = ba.cusip AND e.bid = ba.bid ]]view view id=bid1 schema=cusip maxseq[CDATA[ select b.cusip, maxseq as maxseq from bid as b group by b.cusip ]]view view id=BIDMAX schema=cusip seq srcId bid bidQty[CDATA[ select e.cusip, e.seq, e.srcId, e.bid, e.bidQty from bid1 as b, lastEvents as e where e.seq = b.maxseq ]]view view id=ask schema=cusip ask seq[CDATA[ select ba.cusip as cusip, ba.ask as ask, e.seq from bidask as ba, lastEvents as e WHERE e.cusip = ba.cusip AND e.ask = ba.ask ]]view view id=ask1 schema=cusip maxseq[CDATA[ select a.cusip, maxseq as maxseq from ask as a group by a.cusip ]]view view id=ASKMIN schema=cusip seq srcId ask askQty[CDATA[ select e.cusip, e.seq, e.srcId, e.ask, e.askQty from ask1 as a, lastEvents as e where e.seq = a.maxseq ]]view view id=MAXBIDMINASK schema=cusip bidseq bidSrcId bid askseq askSrcId ask bidQty askQty[CDATA[ select bid.cusip, bid.seq, bid.srcId as bidSrcId, bid.bid, ask.seq, ask.srcId as askSrcId, ask.ask, bid.bidQty, ask.askQty from BIDMAX as bid, ASKMIN as ask where bid.cusip = ask.cusip ]]view query id=BBAQuery[CDATA[ ISTREAMselect bba.cusip, bba.bidseq, bba.bidSrcId, bba.bid, bba.askseq, bba.askSrcId, bba.ask, bba.bidQty, bba.askQty, BBAStrategy as intermediateStrategy, p.seq as