How to Create an Oracle CQL Query

18-6 Oracle Complex Event Processing CQL Language Reference ■ Section 18.2.8, Cache Query For more information, see: ■ Section 18.2.9, Sorting Query Results ■ Section 18.2.10, Detecting Differences in Query Results ■ Section 18.2.11, Parameterized Queries

18.2.1 Query Building Blocks

This section summarizes the basic building blocks that you use to construct an Oracle CQL query, including: ■ Section 18.2.1.1, Select, From, Where Block ■ Section 18.2.1.2, Select Clause ■ Section 18.2.1.3, From Clause ■ Section 18.2.1.4, Where Clause ■ Section 18.2.1.5, Group By Clause ■ Section 18.2.1.6, Order By Clause ■ Section 18.2.1.7, Having Clause ■ Section 18.2.1.8, Binary Clause ■ Section 18.2.1.9, IDStream Clause

18.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::= The sfw_block is made up of the following parts: Oracle CQL Queries, Views, and Joins 18-7 ■ Section 18.2.1.2, Select Clause ■ Section 18.2.1.3, From Clause ■ Section 18.2.1.4, Where Clause ■ Section 18.2.1.5, Group By Clause ■ Section 18.2.1.6, Order By Clause ■ Section 18.2.1.7, Having Clause

18.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::= 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::= on page 20-3

18.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 18.2.1.2, Select Clause . The from_clause may specify one or more comma-delimited relation_variable clauses. from_clause::= For more information, see from_clause::= on page 20-3 18-8 Oracle Complex Event Processing CQL Language Reference relation_variable::= 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 18.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 18–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 18–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: ■ Section 18.2.4, MATCH_RECOGNIZE Query ■ Section 18.2.6, XMLTable Query ■ Section 18.2.7, Function TABLE Query ■ relation_variable::= on page 20-4

18.2.1.4 Where Clause

Use this optional clause to specify conditions that determine when the select_ clause returns results see Section 18.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: ■ opt_where_clause::= on page 20-4 ■ Section 9.1.1, Built-In Aggregate Functions and the Where, Group By, and Having Clauses Oracle CQL Queries, Views, and Joins 18-9