Skip Headers
Oracle® Complex Event Processing CQL Language Reference
11g Release 1 (11.1.1)

Part Number E12048-03
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

17 Oracle CQL Queries, Views, and Joins

You select, process, and filter element data from streams and relations using Oracle CQL queries and views.

A top-level SELECT statement that you create using the QUERY statement is called a query.

A top-level VIEW statement that you create using the VIEW statement is called a view (the Oracle CQL equivalent of a subquery).

A join is a query that combines rows from two or more streams, views, or relations.

This chapter describes:

For more information, see:

17.1 Introduction to Oracle CQL Queries, Views, and Joins

An Oracle CQL query is an operation that you express in Oracle CQL syntax and execute on an Oracle CEP CQL Processor to process data from one or more streams or views. For more information, see Section 17.2, "Queries".

An Oracle CQL view represents an alternative selection on a stream or relation. In Oracle CQL, you use a view instead of a subquery. For more information, see Section 17.3, "Views".

Oracle CEP performs a join whenever multiple streams appear in the FROM clause of the query. For more information, see Section 17.4, "Joins".

Example 17-1 shows typical Oracle CQL queries defined in an Oracle CQL processor component configuration file for the processor named proc.

Example 17-1 Typical Oracle CQL Query

<?xml version="1.0" encoding="UTF-8"?>
<n1:config
    xsi:schemaLocation="http://www.bea.com/ns/wlevs/config/application wlevs_application_config.xsd"
    xmlns:n1="http://www.bea.com/ns/wlevs/config/application"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <processor>
        <name>proc</name>
        <rules>
            <view id="lastEvents" schema="cusip mbid srcId bidQty ask askQty seq"><![CDATA[ 
                select cusip, mod(bid) as mbid, srcId, bidQty, ask, askQty, seq 
                from filteredStream[partition by srcId, cusip rows 1]
            ]]></view>
            <query id="q1"><![CDATA[
                SELECT *
                FROM   lastEvents [Range Unbounded]
                WHERE  price > 10000
            ]]></query>
        </rules>
    </processor>
</n1:config>

As Example 17-1 shows, the rules element contains each Oracle CQL statement in a view or query child element:

Each Oracle CQL statement is contained in a <![CDATA[ ... ]]> tag and does not end in a semicolon (;).

For more information, see:

17.1.1 How to Create an Oracle CQL Query

Typically, you create an Oracle CQL query or view using the Oracle CEP IDE for Eclipse. After deployment, you can add, change, and delete Oracle CQL queries using the Oracle CEP Visualizer.

To create an Oracle CQL query:

  1. Using Oracle CEP IDE for Eclipse, create an Oracle CEP application and Event Processing Network (EPN).

    For more information, see:

  2. In the EPN Editor, right-click an Oracle CQL processor and select Go to Configuration Source as Figure 17-1 shows.

    Figure 17-1 Navigating to the Configuration Source of a Processor from the EPN Editor

    Description of Figure 17-1 follows
    Description of "Figure 17-1 Navigating to the Configuration Source of a Processor from the EPN Editor"

    The EPN Editor opens the corresponding component configuration file for this processor and positions the cursor in the appropriate processor element as Figure 17-2 shows.

    Figure 17-2 Editing the Configuration Source for a Processor

    Description of Figure 17-2 follows
    Description of "Figure 17-2 Editing the Configuration Source for a Processor"

  3. Create queries and views and register user-defined functions and windows.

    For examples, see

  4. Using Oracle CEP IDE for Eclipse, package your Oracle CEP application and deploy to the Oracle CEP server.

    For more information, see "Assembling and Deploying Oracle CEP Applications" in the Oracle CEP Developer's Guide for Eclipse.

  5. After deployment, use the Oracle CEP Visualizer to change, add, and delete queries in the Oracle CEP application.

    For more information, see "Managing Oracle CQL Rules" in the Oracle CEP Visualizer User's Guide.

17.2 Queries

Queries are the principle means of extracting information from data streams and views.

query::=

Surrounding text describes query.gif.

The query clause itself is made up of one of the following parts:

The following sections discuss the basic query types that you can create:

For more information, see:

17.2.1 Query Building Blocks

This section summarizes the basic building blocks that you use to construct an Oracle CQL query, including:

17.2.1.1 Select, From, Where Block

Use the sfw_block to specify the select, from, and optional where clauses of your Oracle CQL query.

sfw_block::=

Surrounding text describes sfw_block.gif.

The sfw_block is made up of the following parts:

17.2.1.2 Select Clause

Use this clause to specify the stream elements you want in the query's result set. The select_clause may specify all stream elements using the * operator or a list of one or more stream elements.

select_clause::=

Surrounding text describes select_clause.gif.

The list of expressions that appears after the SELECT keyword and before the from_clause is called the select list. Within the select list, you specify one or more stream elements in the set of elements you want Oracle CEP to return from one or more streams or views. The number of stream elements, and their datatype and length, are determined by the elements of the select list.

Optionally, specify distinct if you want Oracle CEP to return only one copy of each set of duplicate tuples selected. Duplicate tuples are those with matching values for each expression in the select list.

For more information, see select_clause::=

17.2.1.3 From Clause

Use this clause to specify the streams and views that provide the stream elements you specify in the select_clause (see Section 17.2.1.2, "Select Clause").

The from_clause may specify one or more comma-delimited relation_variable clauses.

from_clause::=

Surrounding text describes from_clause.gif.

For more information, see from_clause::=

relation_variable::=

Surrounding text describes relation_variable.gif.

You can select from any of the data sources that your relation_variable clause specifies.

You can use the relation_variable clause AS operator to define an alias to label the immediately preceding expression in the select list so that you can reference the result by that (see Section 2.8.1.1, "Aliases in the relation_variable Clause").

If you create a join (see Section 17.4, "Joins") between two or more streams, view, or relations that have some stream element names in common, then you must qualify stream element names with the name of their stream, view, or relation. Example 17-2 shows how to use stream names to distinguish between the customerID stream element in the OrderStream and the customerID stream element in the CustomerStream.

Example 17-2 Fully Qualified Stream Element Names

<query id="q0"><![CDATA[ 
    select * from OrderStream, CustomerStream 
    where 
        OrderStream.customerID = CustomerStream.customerID
]]></query>

Otherwise, fully qualified stream element names are optional. However, Oracle recommends that you always qualify stream element references explicitly. Oracle CEP often does less work with fully qualified stream element names.

For more information, see:

17.2.1.4 Where Clause

Use this optional clause to specify conditions that determine when the select_clause returns results (see Section 17.2.1.2, "Select Clause").

Because Oracle CQL applies the WHERE clause before GROUP BY or HAVING, if you specify an aggregate function in the SELECT clause, you must test the aggregate function result in a HAVING clause, not the WHERE clause.

For more information, see:

17.2.1.5 Group By Clause

Use this optional clause to group (partition) results. This clause does not guarantee the order of the result set. To order the groupings, use the order by clause.

Because Oracle CQL applies the WHERE clause before GROUP BY or HAVING, if you specify an aggregate function in the SELECT clause, you must test the aggregate function result in a HAVING clause, not the WHERE clause.

For more information, see:

17.2.1.6 Order By Clause

Use this optional clause to order all results or the top-n results.

For more information, see:

17.2.1.7 Having Clause

Use this optional clause to restrict the groups of returned stream elements to those groups for which the specified condition is TRUE. If you omit this clause, then Oracle CEP returns summary results for all groups.

Because Oracle CQL applies the WHERE clause before GROUP BY or HAVING, if you specify an aggregate function in the SELECT clause, you must test the aggregate function result in a HAVING clause, not the WHERE clause.

For more information, see:

17.2.1.8 Binary Clause

Use the binary clause to perform set operations on the tuples that two queries or views return, including:

  • EXCEPT

  • MINUS

  • INTERSECT

  • UNION and UNION ALL

  • IN and NOT IN

For more information, see binary::=.

17.2.1.9 IDStream Clause

Use this clause to take either a select-from-where clause or binary clause and return its results as one of IStream or DStream relation-to-stream operators.

You can succinctly detect differences in query output by combining an IStream or Dstream operator with the using_clause.

For more information, see:

17.2.2 Simple Query

Example 17-3 shows a simple query that selects all stream elements from a single stream.

Example 17-3 Simple Query

<query id="q0"><![CDATA[ 
    select * from OrderStream where orderAmount > 10000.0
]]></query>

For more information, see "Query".

17.2.3 Built-In Window Query

Example 17-4 shows a query that selects all stream elements from stream S2, with schema (c1 integer, c2 float), using a built-in tuple-based stream-to-relation window operator.

Example 17-4 Built-In Window Query

<query id="BBAQuery"><![CDATA[ 
    create query q209 as select * from S2 [range 5 minutes] where S2.c1 > 10
]]></query>

For more information, see:

17.2.4 MATCH_RECOGNIZE Query

Example 17-5 shows a query that uses the MATCH_RECOGNIZE clause to express complex relationships among the stream elements of ItemTempStream.

Example 17-5 MATCH_RECOGNIZE Query

<query id="detectPerish"><![CDATA[ 
  select its.itemId
  from tkrfid_ItemTempStream MATCH_RECOGNIZE (
      PARTITION BY itemId
      MEASURES A.itemId as itemId
      PATTERN (A B* C)
      DEFINE
          A  AS  (A.temp >= 25),
          B  AS  ((B.temp >= 25) and (to_timestamp(B.element_time) - to_timestamp(A.element_time) < INTERVAL "0 00:00:05.00" DAY TO SECOND)),
          C  AS  (to_timestamp(C.element_time) - to_timestamp(A.element_time) >= INTERVAL "0 00:00:05.00" DAY TO SECOND)
  ) as its
]]></query>

For more information, see:

17.2.5 Relational Database Table Query

Using an Oracle CQL processor, you can specify a relational database table as an event source. You can query this event source, join it with other event sources, and so on.

For example, assume that you create the table you want to access using the SQL statement that Example 17-6 shows.

Example 17-6 Table Create SQL Statement

create table Stock (symbol varchar(16), exchange varchar(16));

After configuration, you can define Oracle CQL queries that access the Stock table as if it was just another event stream. Example 17-7 shows a query that joins one event stream ExchangeStream with the Stock table:

Example 17-7 Oracle CQL Query on Relational Database Table Stock

SELECT ExchangeStream.symbol, ExchangeStream.price, Stock.exchange
FROM   ExchangeStream [Now], Stock
WHERE  ExchangeStream.symbol = Stock.symbol

Oracle CEP relational database table event sources are pull data sources: that is, Oracle CEP will periodically poll the event source.

Note:

Because changes in the table source are not coordinated in time with stream data, you may only use a Now window. For more information, see "S[now]".

For more information, see:

17.2.6 XMLTable Query

Example 17-8 shows a view v1 and a query q1 on that view. The view selects from a stream S1 of xmltype stream elements. The view v1 uses the XMLTABLE clause to parse data from the xmltype stream elements using XPath expressions. Note that the data types in the view's schema match the datatypes of the parsed data in the COLUMNS clause. The query q1 selects from this view as it would from any other data source. The XMLTABLE clause also supports XML namespaces.

Example 17-8 XMLTABLE Query

<view id="v1" schema="orderId LastShares LastPrice"><![CDATA[ 
    select 
        X.OrderId, 
        X.LastShares, 
        X.LastPrice 
    from 
        S1 
    XMLTABLE (
        "//FILL" 
        PASSING BY VALUE 
            S1.c1 as "." 
        COLUMNS 
            OrderId char(16) PATH "fn:data(../@ID)", 
            LastShares integer PATH "fn:data(@LastShares)", 
            LastPrice float PATH "fn:data(@LastPx)"
    ) as X
]]></view>

<query id="q1"><![CDATA[ 
    IStream(
        select 
            orderId, 
            sum(LastShares * LastPrice), 
            sum(LastShares * LastPrice) / sum(LastShares)
        from 
            v1[now] 
        group by orderId
    )
]]></query>

For more information, see:

17.2.7 Function TABLE Query

Use the TABLE clause to access the multiple rows returned by a built-in or user-defined function in the FROM clause of an Oracle CQL query. The TABLE clause converts the set of returned rows into an Oracle CQL relation. Because this is an external relation, you must join the TABLE function clause with a stream.

table_clause::=

Surrounding text describes table_clause.gif.

(object_expr::=, identifier::=, datatype::=)

Note the following:

  • The function must return an array type or Collection type.

  • You must join the TABLE function clause with a stream.

Example 17-9 shows a data cartridge TABLE clause that invokes the Oracle Spatial data cartridge method getContainingGeometries, passing in one parameter (InputPoints.point). The return value of this method, a Collection, is aliased as validGeometries. The relation that the TABLE clause returns is aliased as R2.

Example 17-9 Data Cartridge TABLE Query

<query id="q1"><![CDATA[ 
RSTREAM (
    SELECT 
        R2.validGeometries.shape as containingGeometry,
        R1.point as inputPoint
    FROM 
        InputPoints[now] as R1,
        TABLE (getContainingGeometries@spatial (InputPoints.point) as validGeometries) AS R2
)
]]></query>

Example 17-10 shows an invalid data cartridge TABLE query that fails to join the data cartridge TABLE clause with another stream because the function getAllGeometries@spatial was called without any parameters. Oracle CEP invokes the data cartridge method only on the arrival of elements on the joined stream.

Example 17-10 Invalid Data Cartridge TABLE Query

<query id="q2"><![CDATA[ 
RSTREAM (
    SELECT 
        R2.validGeometries.shape as containingGeometry
    FROM 
        TABLE (getAllGeometries@spatial () as validGeometries) AS R2
)
]]></query>

For more examples, see:

For more information, see:

17.2.8 Cache Query

Using an Oracle CQL processor, you can specify a cache as an event source. You can query this event source and join it with other event sources using a Now window only.

Oracle CEP cache event sources are pull data sources: that is, Oracle CEP will periodically poll the event source.

For more information, see Section 17.5, "Oracle CQL Queries and the Oracle CEP Server Cache".

17.2.9 Sorting Query Results

Use the ORDER BY clause to order the rows selected by a query.

order_by_clause::=

Surrounding text describes order_by_clause.gif.

(order_by_list::=)

Sorting by position is useful in the following cases:

  • To order by a lengthy select list expression, you can specify its position in the ORDER BY clause rather than duplicate the entire expression.

  • For compound queries containing set operators UNION, INTERSECT, MINUS, or UNION ALL, the ORDER BY clause must specify positions or aliases rather than explicit expressions. Also, the ORDER BY clause can appear only in the last component query. The ORDER BY clause orders all rows returned by the entire compound query.

The mechanism by which Oracle CEP sorts values for the ORDER BY clause is specified by your Java locale.

17.2.10 Detecting Differences in Query Results

Use the DIFFERENCE USING clause to succinctly detect differences in the IStream or DStream of a query.

using_clause::=

Surrounding text describes using_clause.gif.

(usinglist::=)

Consider the query that Example 17-11 shows.

Example 17-11 DIFFERENCE USING Clause

<query id="q0">
    ISTREAM (
        SELECT c1 FROM S [RANGE 1 NANOSECONDS]
    )    DIFFERENCE USING (c1)
</query>

Table 17-1 shows sample input for this query. The Relation column shows the contents of the relation S [RANGE 1 NANOSECONDS] and the Output column shows the query results after the DIFFERENCE USING clause is applied. This clause allows you to succinctly detect only differences in the IStream output.

Table 17-1 DIFFERENCE USING Clause Affect on IStream

Input Relation Output

1000:    +5

{5}

+5

1000:    +6

{5, 6}

+6

1000:    +7

{5, 6, 7}

+7

1001:    +5

{5, 6, 7, 5}

 

1001:    +6

{5, 6, 7, 5, 6}

 

1001:    +7

{5, 6, 7, 5, 6, 7}

 

1001:    +8

{5, 6, 7, 5, 6, 7, 8}

+8

1002:    +5

{5, 6, 7, 5, 6, 7, 8, 5}

 

1003:    -5

{5, 6, 7, 5, 6, 7, 8}

 

1003:    -5

{5, 6, 7, 6, 7, 8}

 

1003:    -5

{6, 7, 6, 7, 8}

 

1003:    -6

{6, 7, 7, 8}

 

1003:    -6

{7, 7, 8}

 

1003:    -7

{7, 8}

 

1003:    -7

{8}

 

1003:    -8

{}

 

1004:    +5

{5}

+5


When you specify the usinglist in the DIFFERENCE USING clause, you may specify columns by:

  • attribute name: use this option when you are selecting by attribute name.

    Example 17-12 shows attribute name c1 in the DIFFERENCE USING clause usinglist.

  • alias: use this option when you want to include the results of an expression where an alias is specified.

    Example 17-12 shows alias logval in the DIFFERENCE USING clause usinglist.

  • position: use this option when you want to include the results of an expression where no alias is specified.

    Specify position as a constant, positive integer starting at 1, reading from left to right.

    Example 17-12 specifies the result of expression funct(c2, c3) by its position (3) in the DIFFERENCE USING clause usinglist.

Example 17-12 Specifying the usinglist in a DIFFERENCE USING Clause

<query id="q1">
    ISTREAM (
        SELECT c1, log(c4) as logval, funct(c2, c3) FROM S [RANGE 1 NANOSECONDS]
    )    DIFFERENCE USING (c1, logval, 3)
</query>

You can use the DIFFERENCE USING clause with both IStream and DStream operators.

For more information, see:

17.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.

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 17.2, "Queries".

For complete details on the view statement, see "View".

In Example 17-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 17-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, max(bid), min(ask) 
    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, max(seq) 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, max(seq) 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[ 
    ISTREAM(select bba.cusip, bba.bidseq, bba.bidSrcId, bba.bid, bba.askseq, bba.askSrcId, bba.ask, bba.bidQty, bba.askQty, "BBAStrategy" as intermediateStrategy, p.seq as correlationId, 1 as priority 
    from MAXBIDMINASK as bba, filteredStream[rows 1] as p where bba.cusip = p.cusip)
]]></query>

Using this technique, you can achieve the same results as in the subquery case. However, using views you can better control the complexity of queries and reuse views by name in other queries.

17.3.1 Views and Joins

If you create a join between two or more views that have some stream element names in common, then you must qualify stream element names with names of streams. Example 17-14 shows how to use view names to distinguish between the seq stream element in the BIDMAX view and the seq stream element in the ASKMIN view.

Example 17-14 Using View Names to Distinguish Between Stream Elements of the Same Name

<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>

Otherwise, fully qualified stream element names are optional. However, it is a best practice to always qualify stream element references explicitly. Oracle CEP often does less work with fully qualified stream element names.

For more information, see Section 17.4, "Joins".

17.3.2 Views and Schemas

You may define the optional schema of the view using a space delimited list of event attribute names as Example 17-15 shows.

Example 17-15 Schema With Event Attribute Names Only

<view id="MAXBIDMINASK" schema="cusip bidseq"><![CDATA[ 
    select ... 
]]></view>

17.4 Joins

A join is a query that combines rows from two or more streams, views, or relations. Oracle CEP performs a join whenever multiple streams appear in the FROM clause of the query. The select list of the query can select any stream elements from any of these streams. If any two of these streams have a stream element name in common, then you must qualify all references to these stream elements throughout the query with stream names to avoid ambiguity.

If you create a join between two or more streams, view, or relations that have some stream element names in common, then you must qualify stream element names with the name of their stream, view, or relation. Example 17-16 shows how to use stream names to distinguish between the customerID stream element in the OrderStream stream and the customerID stream element in the CustomerStream stream.

Example 17-16 Fully Qualified Stream Element Names

<query id="q0"><![CDATA[ 
    select * from OrderStream[range 5] as orders, CustomerStream[range 3] as customers where 
        orders.customerID = customers.customerID
]]></query>

Otherwise, fully qualified stream element names are optional. However, Oracle recommends that you always qualify stream element references explicitly. Oracle CEP often does less work with fully qualified stream element names.

Oracle CEP supports the following types of joins:

Note:

When joining against a cache, you must observe additional query restrictions as Section 17.5.1, "Creating Joins Against the Cache" describes.

17.4.1 Inner Joins

By default, Oracle CEP performs an inner join (sometimes called a simple join): a join of two or more streams that returns only those stream elements that satisfy the join condition.

Example 17-17 shows how to create a query q4 that uses an inner join between streams S0, with schema (c1 integer, c2 float), and S1, with schema (c1 integer, c2 float).

Example 17-17 Inner Joins

<query id="q4"><![CDATA[ 
    select * 
        from 
            S0[range 5] as a, 
            S1[range 3] as b 
        where 
            a.c1+a.c2+4.9 = b.c1 + 10
]]></query>

17.4.2 Outer Joins

An outer join extends the result of a simple join. An outer join returns all rows that satisfy the join condition and also returns some or all of those rows from one table for which no rows from the other satisfy the join condition.

You specify an outer join in the FROM clause of a query using LEFT or RIGHT OUTER JOIN ... ON syntax.

from_clause::=

Surrounding text describes from_clause.gif.

(non_mt_relation_list::=, relation_variable::=, non_mt_cond_list::=)

Example 17-18 shows how to create a query q5 that uses a left outer join between streams S0, with schema (c1 integer, c2 float), and S1, with schema (c1 integer, c2 float).

Example 17-18 Outer Joins

<query id="q5"><![CDATA[ 
    SELECT a.c1+b.c1 
    FROM S0[range 5] AS a LEFT OUTER JOIN S1[range 3] AS b ON b.c2 = a.c2
    WHERE b.c2 > 3
]]></query>

Use the ON clause to specify a join condition. Doing so lets you specify join conditions separate from any search or filter conditions in the WHERE clause.

You can perform the following types of outer join:

17.4.2.1 Left Outer Join

To write a query that performs an outer join of streams A and B and returns all stream elements from A (a left outer join), use the LEFT OUTER JOIN syntax in the FROM clause as Example 17-19 shows. For all stream elements in A that have no matching stream elements in B, Oracle CEP returns null for any select list expressions containing stream elements of B.

Example 17-19 Left Outer Joins

<query id="q5"><![CDATA[ 
    SELECT a.c1+b.c1 
    FROM S0[range 5] AS a LEFT OUTER JOIN S1[range 3] AS b  ON b.c2 = a.c2
    WHERE b.c2 > 3
]]></query>

17.4.2.2 Right Outer Join

To write a query that performs an outer join of streams A and B and returns all stream elements from B (a right outer join), use the RIGHT OUTER JOIN syntax in the FROM clause as Example 17-20 shows. For all stream elements in B that have no matching stream elements in A, Oracle CEP returns null for any select list expressions containing stream elements of A.

Example 17-20 Right Outer Joins

<query id="q5"><![CDATA[ 
    SELECT a.c1+b.c1 
    FROM S0[range 5] AS a RIGHT OUTER JOIN S1[range 3] AS b ON b.c2 = a.c2
    WHERE b.c2 > 3
]]></query>

17.4.2.3 Outer Join Look-Back

You can create an outer join that refers or looks-back to a previous outer join as Example 17-21 shows.

Example 17-21 Outer Join Look-Back

<query id="q5"><![CDATA[ 
    SELECT R1.c1+R2.c1 
    FROM S0[rows 2] as R1 LEFT OUTER JOIN S1[rows 2] as R2 on R1.c2 = R2.c2 RIGHT OUTER JOIN S2[rows 2] as R3 on R2.c2 = R3.c22
    WHERE R2.c2 > 3
]]></query>

17.5 Oracle CQL Queries and the Oracle CEP Server Cache

You can access an Oracle CEP cache from an Oracle CQL statement or user-defined function.

This section describes:

For more information, see:

17.5.1 Creating Joins Against the Cache

When writing Oracle CQL queries that join against a cache, you must observe the following restrictions:

For more information, see Section 17.4, "Joins".

17.5.1.1 Cache Key First and Simple Equality

The complex predicate's first subclause (from the left) with a comparison operation over a cache key attribute may only be a simple equality predicate.

The following predicate is invalid because the predicate is not the first sub-clause (from the left) which refers to cache attributes:

... S.c1 = 5 AND CACHE.C2 = S.C2 AND CACHE.C1 = S.C1 ...

However, the following predicate is valid:

... S.c1 = 5 AND CACHE.C1 = S.C1 AND CACHE.C2 = S.C2 ...

17.5.1.2 No Arithmetic Operations on Cache Keys

The subclause may not have any arithmetic operations on a cache key attribute.

The following predicate is invalid because arithmetic operations are not allowed on cache key attributes:

... CACHE.C1 + 5 = S.C1 AND CACHE.C2 = S.C2 ...

17.5.1.3 No Full Scans

The complex predicate must not require a full scan of the cache.

Assume that your cache has cache key C1.

The following predicates are invalid. Because they do not use the cache key attribute in comparisons, they must scan through the whole cache which is not allowed.

... CACHE.C2 = S.C1 ...

... CACHE.C2 > S.C1 ...

... S.C1 = S.C2 ...

... S.C1 = CACHE.C2 AND S.C2 = CACHE.C2 ...

The following predicates are also invalid. Although they do use the cache key attribute in comparisons, they use inequality operations that must scan through the whole cache which is not allowed.

... CACHE.C1 != S.C1 ...

... CACHE.C1 > 5 ...

... CACHE.C1 + 5 = S.C1 ...

The following predicate is also invalid. Although they do use the cache key attribute in comparisons, the first subclause referring to the cache attributes does not refer to the cache key attribute (in this example, C1). That is, the first subclause refers to C2 which is not a cache key and the cache key comparison subclause (CACHE.C1 = S.C1) appears after the non-key comparison subclause.

... CACHE.C2 = S.C2 AND CACHE.C1 = S.C1 ...

17.5.1.4 Multiple Conditions and Inequality

To support multiple conditions, inequality, or both, you must make the first sub-clause an equality predicate comparing a cache key value and specify the rest of the predicate subclauses separated by one AND operator.

The following are valid predicates:

... S.c1 = 5 AND CACHE.C1 = S.C1 AND CACHE.C2 > S.C2 ...

... CACHE.C1 = S.C1 AND CACHE.C2 = S.C2 ...

... S.c1 = 5 AND CACHE.C1 = S.C1 AND CACHE.C2 != S.C2 ...

17.6 Oracle CQL Queries and Relational Database Tables

You can access a relational database table from an Oracle CQL statement.

For a query that joins against a relational database table, Oracle CQL supports all kinds of complex predicates.

For more information, see "Configuring an Oracle CQL Processor Table Source" in the Oracle CEP Developer's Guide for Eclipse.

17.7 Oracle CQL Queries and Oracle Data Cartridges

You can access Oracle CQL data cartridges from an Oracle CQL statement.

For more information, see: