7 Common Oracle CQL DDL Clauses

This chapter provides a reference to clauses in the data definition language (DDL) in Oracle Continuous Query Language (Oracle CQL).

This chapter includes the following section:

7.2 array_type

Purpose

Use the array_type clause to specify an Oracle CQL data cartridge type composed of a sequence of complex_type components, all of the same type.

Note:

Oracle CQL supports single-dimension arrays only. That is, you can use java.lang.String[] but not java.lang.String[][].

Prerequisites

None.

Syntax

array_type::=

array type

Semantics

Array Declaration

You declare an array type using the qualified_type_name of the Oracle CQL data cartridge complex_type. Only arrays of complextype are supported: you cannot declare an array of Oracle CQL simple types unless there is an equivalent type defined in the Oracle CQL Java data cartridge.

Array Access

You access a complex_type array element by integer index. The index begins at 0 or 1 depending on the data cartridge implementation.

There is no support for the instantiation of new array type instances directly in Oracle CQL at the time you access an array. For example, the following is not allowed:

SELECT java.lang.String[10] ...

Examples

The following example shows how to create an event type as a Java class that specifies an event property as an array of Oracle CQL data cartridge complex type MyClass defined in package com.mypackage.

package com.myapplication.event;

import java.util.Date;

public final class MarketEvent {
    private final String symbol;
    private final Double price;
    private final com.mypackage.MyClass[] a1;

    public MarketEvent(...) {
        ...
        }
    ...
}

Array Declaration Example: Oracle CQL Simple Type

Only arrays of Oracle CQL data cartridge types are supported: you cannot declare an array of Oracle CQL simple types.

int[] a1

However, you can work around this by using the Oracle CQL Java data cartridge and referencing the Java equivalent of the simple type, if one exists:

int@java[] a1

For more information on the @ syntax, see link::=.

Array Access Examples

The following example shows how to register the following queries that use Oracle CQL data cartridge complex type array access:

  • View v1 accesses the third element of the array a1. This array contains instances of Oracle CQL data cartridge complex type com.mypackage.MyClass.

  • Query q1 accesses the first element of the array field1. This array is defined on Oracle CQL data cartridge complex type a1.

<view id="v1" schema="symbol price a1"><![CDATA[ 
    IStream(select symbol, price, a1[3] from S1[range 10 slide 10]) 
]]></view>
<query id="q1"><![CDATA[ 
    SELECT a1.field1[1] …
]]></query>

7.3 attr

Purpose

Use the attr clause to specify a stream element or pseudocolumn.

You can use the attr clause in the following Oracle CQL statements:

Prerequisites

None.

Syntax

Figure 7-1 attr::=

attr

identifier::= and Example 7-1.

element time

Semantics

identifier

Specify the identifier of the stream element.

You can specify

  • StreamOrViewName.ElementName

  • ElementName

  • CorrelationName.PseudoColumn

  • PseudoColumn.

For examples, see Examples.

Example 7-1 pseudo_column

Specify the timestamp associated with a specific stream element, all stream elements, or the stream element associated with a correlation name in a MATCH_RECOGNIZE clause.

For examples, see:

For more information, see Pseudocolumns.

Examples

Given the stream, valid attribute clauses are:

  • ItemTempStream.temp

  • temp

  • B.element_time

  • element_time

<view id="ItemTempStream" schema="itemId temp"><![CDATA[ 
    IStream(select * from ItemTemp) 
]]></view>
<query id="detectPerish"><![CDATA[ 
  select its.itemId
  from 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>

7.4 attrspec

Purpose

Use the attrspec clause to define the identifier and data type of a stream element.

Prerequisites

None.

Syntax

Figure 7-2 attrspec::=

attr spec

(fixed_length_datatype::= and variable_length_datatype::=).

Semantics

identifier

Specify the identifier of the stream element.

fixed_length_datatype

Specify the stream element data type as a fixed-length data type.

For syntax, see fixed_length_datatype::= .

variable_length_datatype

Specify the stream element data type as a variable-length data type.

For syntax, see variable_length_datatype::=.

integer

Specify the length of the variable-length data type.

7.5 complex_type

Purpose

Use the complex_type clause to specify an Oracle CQL data cartridge type that defines:

  • member fields (static or instance)

  • member methods (static or instance)

  • constructors.

The type of a field, and the return type and parameter list of a method may be complex types or simple types.

A complex type is identified by its qualified type name (set of identifiers separated by a period ".") and the optional name of the data cartridge to which it belongs (see link::=). If you do not specify a link name, then Oracle Event Processing assumes that the complex type is a Java class (that is, Oracle Event Processing assumes that the complex type belongs to the Java data cartridge).

Prerequisites

The Oracle CQL data cartridge that provides the complextype must be loaded by Oracle Event Processing server at runtime.

Syntax

complex_type::=

field name
complex type

(link::=)

Semantics

fieldname

Use the fieldname clause to specify a static field of an Oracle CQL data cartridge complex type.

Field Access

You cannot use a complex type l-value generated in expressions within an ORDER BY clause. Currently, only expressions within a SELECT clause and a WHERE clause may generate a complex type l-value.

You may access only a static field using qualified_type_name. To access a non-static field, you must first instantiate the complex type.

Method Access

Accessing complex type setter methods may cause side effects. Side effects decrease the opportunities for concurrency and sharing. For example, if you invoke a setter method and change the value of a view attribute (such as an event property) shared by different queries that depend on the view, then the query results may change as a side effect of your method invocation.

You may access only a static method using qualified_type_name. To access a non-static field, you must first instantiate the complex type.

Constructor Invocation

You may access only a static fields and static methods using qualified_type_name. To access a non-static field or non-static method, you must first instantiate the complex type by invoking one of its constructors.

Examples

Field Access Examples: complex_type

The following example shows how to register the following queries that use Oracle CQL data cartridge complex type field access:

  • Query q1 accesses field myField from Oracle CQL data cartridge complex type a1.

  • Query q2 accesses field myField defined on the Oracle CQL data cartridge complex type returned by the method function-returning-object.

    Query q3 accesses field myNestedField defined on the Oracle CQL data cartridge complex type myField which is defined on Oracle CQL data cartridge complex type a1.

  • Query q4 accesses the static field myStaticField defined in the class MyType in package com.myPackage. Note that a link (@myCartridge) is necessary in the case of a static field.

<query id="q1"><![CDATA[ 
    SELECT a1.myField …
]]></query>
<query id="q2"><![CDATA[ 
    SELECT function-returning-object().myField …
]]></query>
<query id="q3"><![CDATA[ 
    SELECT a1.myField.myNestedField …
]]></query>
<query id="q4"><![CDATA[ 
    SELECT com.myPackage.MyType.myStaticField@myCartridge …
]]></query>

Method Access Examples: complex_type

The following example shows how to register the following queries that use Oracle CQL data cartridge complex type method access:

  • Query q1 accesses method myMethod defined on Oracle CQL data cartridge complex type a1. This query accesses the method with an empty parameter list.

  • Query q2 accesses method myMethod defined on Oracle CQL data cartridge complex type a1 with a different signature than in query q1. In this case, the query accesses the method with a three-argument parameter list.

  • Query q3 accesses static method myStaticMethod defined on Oracle CQL data cartridge complex type MyType. This query accesses the method with a single parameter. Note that a link (@myCartridge) is necessary in the case of a static method.

<query id="q1"><![CDATA[ 
    SELECT a1.myMethod() … 
]]></query>
<query id="q2"><![CDATA[ 
    SELECT a1.myMethod(a2, “foo", 10) …
]]></query>
<query id="q3"><![CDATA[ 
    SELECT myPackage.MyType.myStaticMethod@myCartridge("foo") …
]]></query>

Constructor Invocation Examples: complex_type

The following example shows how to register the following queries that use Oracle CQL data cartridge complex type constructor invocation:

  • Query q1 invokes the constructor String defined in package java.lang. In this case, the query invokes the constructor with an empty argument list.

  • Query q2 invokes the constructor String defined in package java.lang. In this case, the query invokes the constructor with a single argument parameter list and invokes the non-static method substring defined on the returned String instance.

<query id="q1"><![CDATA[ 
    SELECT java.lang.String() …
]]></query>
<query id="q2"><![CDATA[ 
    SELECT java.lang.String(“food").substring(0,1) …
]]></query>

7.6 const_bigint

Purpose

Use the const_bigint clause to specify a big integer numeric literal.

You can use the const_bigint clause in the following Oracle CQL statements:

For more information, see Numeric Literals.

Prerequisites

None.

Syntax

const_bigint::=

const bigint

7.7 const_int

Purpose

Use the const_int clause to specify an integer numeric literal.

You can use the const_int clause in the following Oracle CQL statements:

For more information, see Numeric Literals.

Prerequisites

None.

Syntax

const_int::=

const int

7.8 const_string

Purpose

Use the const_string clause to specify a constant String text literal.

You can use the const_string clause in the following Oracle CQL statements:

For more information, see Text Literals.

Prerequisites

None.

Syntax

Figure 7-3 const_string::=

const string

7.9 const_value

Purpose

Use the const_value clause to specify a literal value.

You can use the const_value clause in the following Oracle CQL statements:

For more information, see Literals.

Prerequisites

None.

Syntax

Figure 7-4 const_value::=

const value

Example 7-2.

Figure 7-5 interval_value

interval value

Example 7-2 interval_value

Specify an interval constant value as a quoted string. For example:

INTERVAL '4 5:12:10.222' DAY TO SECOND(3)

For more information, see Interval Literals.

const_string

Specify a quoted String constant value.

For more information, see Text Literals.

null

Specify a null constant value.

For more information, see Nulls.

const_int

Specify an int constant value.

For more information, see Numeric Literals.

bigint

Specify a bigint constant value.

For more information, see Numeric Literals.

float

Specify a float constant value.

For more information, see Numeric Literals.

7.10 identifier

Purpose

Use the identifier clause to reference an existing Oracle CQL schema object.

You can use the identifier clause in the following Oracle CQL statements:

Prerequisites

The schema object must already exist.

Syntax

Figure 7-6 identifier::=

identifier

const_string and Example 7-3.

Example 7-3 unreserved_keyword::=

unreserved keyword

Semantics

const_string

Specify the identifier as a String.

For more information, see Schema Object Naming Rules.

[A-Z]

Specify the identifier as a single uppercase letter.

unreserved_keyword

These are names that you may use as identifiers.

For more information, see:

reserved_keyword

These are names that you may not use as identifiers, because they are reserved keywords: add, aggregate, all, alter, and, application, as, asc, avg, between, bigint, binding, binjoin, binstreamjoin, boolean, by, byte, callout, case, char, clear, columns, constraint, content, count, create, day, days, decode, define, derived, desc, destination, disable, distinct, document, double, drop, dstream, dump, duration, duration, element_time, else, enable, end, evalname, event, events, except, external, false, first, float, from, function, group, groupaggr, having, heartbeat, hour, hours, identified, implement, in, include, index, instance, int, integer, intersect, interval, is, istream, java, key, language, last, level, like, lineage, logging, match_recognize, matches, max, measures, metadata_query, metadata_system, metadata_table, metadata_userfunc, metadata_view, metadata_window, microsecond, microseconds, millisecond, milliseconds, min, minus, minute, minutes, monitoring, multiples, nanosecond, nanoseconds, not, now, null, nulls, object, of, on, operator, or, order, orderbytop, output, partition, partitionwin, partnwin, passing, path, pattern, patternstrm, patternstrmb, prev, primary, project, push, query, queue, range, rangewin, real, register, relation, relsrc, remove, return, returning, rows, rowwin, rstream, run, run_time, sched_name, sched_threaded, schema, second, seconds, select, semantics, set, silent, sink, slide, source, spill, start, stop, storage, store, stream, strmsrc, subset, sum, synopsis, system, systemstate, then, time, time_slice, timeout, timer, timestamp, timestamped, to, true, trusted, type, unbounded, union, update, using, value, view, viewrelnsrc, viewstrmsrc, wellformed, when, where, window, xmlagg, xmlattributes, xmlcolattval, xmlconcat, xmldata, xmlelement, xmlexists, xmlforest, xmlparse, xmlquery, xmltable, xmltype, or xor.

7.11 multi_paramspec_list

Purpose

Use the multi_paramspec_list clause to specify a stream element identifier and data type of two or more stream elements. To specify the identifier and data type of a single stream elements, use the paramspec clause.

Prerequisites

The stream must already exist.

Syntax

MULTI PARAM SPEC LIST SYNTAX

Semantics

paramspec

Specify one or more stream elements.

7.12 l-value

Purpose

Use the l-value clause to specify an integer literal.

Prerequisites

None.

Syntax

l-value::=

I value

7.13 methodname

Purpose

Use the methodname clause to specify a method of an Oracle CQL data cartridge complex type.

Prerequisites

None.

Syntax

methodname::=

method name

(link::=)

7.14 non_mt_arg_list

Purpose

Use the non_mt_arg_list clause to specify one or more arguments as arithmetic expressions involving stream elements.

You can use the non_mt_arg_list clause in the following Oracle CQL statements:

Prerequisites

If any stream elements are referenced, the stream must already exist.

Syntax

non_mt_arg_list::=

non mt arg list

(arith_expr::=)

Semantics

arith_expr

Specify the arithmetic expression that resolves to the argument value.

7.15 non_mt_attr_list

Purpose

Use the non_mt_attr_list clause to specify one or more arguments as stream elements directly.

You can use the non_mt_attr_list clause in the following Oracle CQL statements:

Prerequisites

If any stream elements are referenced, the stream must already exist.

Syntax

Figure 7-7 non_mt_attr_list::=

non mt attr list

Semantics

attr

Specify the argument as a stream element directly.

7.16 non_mt_attrname_list

Purpose

Use the non_mt_attrname_list clause to one or more stream elements by name.

You can use the non_mt_attrname_list clause in the following Oracle CQL statements:

Prerequisites

If any stream elements are referenced, the stream must already exist.

Syntax

Figure 7-8 non_mt_attrname_list::=

non mt attr name list

Semantics

identifier

Specify the stream element by name.

7.17 non_mt_attrspec_list

Purpose

Use the non_mt_attrspec_list clause to specify one or more attribute specifications that define the identifier and data type of stream elements.

You can use the non_mt_attrspec_list clause in the following Oracle CQL statements:

Prerequisites

If any stream elements are referenced, the stream must already exist.

Syntax

non_mt_attrspec_list::=

non mt attr spec list

Semantics

attrspec

Specify the attribute identifier and data type.

7.18 non_mt_cond_list

Purpose

Use the non_mt_cond_list clause to specify one or more conditions using any combination of logical operators AND, OR, XOR and NOT.

You can use the non_mt_cond_list clause in the following Oracle CQL statements:

For more information, see Conditions.

Prerequisites

None.

Syntax

non_mt_cond_list::=

non mt cond list

(condition::=, between_condition::=)

Semantics

condition

Specify a comparison condition.

For more information, see Comparison Conditions.

For syntax, see condition::=.

between_condition

Specify a condition that tests for inclusion in a range.

For more information, see Range Conditions.

For syntax, see between_condition::=.

7.19 out_of_line_constraint

Purpose

Use this out_of_line_constraint clause to restrict a tuple of any data type by a primary key integrity constraint.

If you plan to configure a query on a relation with USE UPDATE SEMANTICS, you must declare one or more stream elements as a primary key. Use this constraint to specify a compound primary key made up of one or more stream element values.

You can use the out_of_line_constraint clause in the following Oracle CQL statements:

For more information, see:

Prerequisites

A tuple that you specify with an out_of_line_constraint may not contain a null value.

Syntax

out_of_line_constraint::=

out of line constraint

Semantics

non_mt_attrname_list

Specify one or more tuples to restrict by a primary key integrity constraint.

7.20 param_list

Purpose

Use the param_list clause to specify a comma-separated list of zero or more parameters, similar to a function parameter list, for an Oracle CQL data cartridge complex type method or constructor.

You can use the param_list clause in the following Oracle CQL data cartridge statements:

Prerequisites

None.

Syntax

param_list::=

param list

(arith_expr::=).

7.21 paramspec

Purpose

Use the paramspec clause to specify a stream element identifier and data type. To specify the identifier and data type of two or more stream elements, use a multi_paramspec_list .

Prerequisites

None.

Syntax

paramspec::=

paramspec

Semantics

identifier

Specify the stream element identifier.

datatype

Specify the stream element data type.

For syntax, see datatype::=.

7.22 qualified_type_name

Purpose

Use the qualified_type_name clause to specify a fully specified type name of an Oracle CQL data cartridge complex type, for example java.lang.String. Use the qualified_type_name when invoking Oracle CQL data cartridge static fields, static methods, or constructors.

There is no default package. For example, using the Java data cartridge, you must specify java.lang when referencing the class String. To be able to distinguish a reserved word from a qualified type, all qualified types must have at least two identifiers, that is, there must be at least one period (.) in a qualified name.

Prerequisites

None.

Syntax

qualified_type_name::=

qualified type name

(arith_expr::= and link::=)

identifier
identifier

Semantics

package_name

Use the package_name clause to specify the name of an Oracle CQL data cartridge package.

class_name

Use the class_name clause to specify the name of an Oracle CQL data cartridge Class.

7.23 query_ref

Purpose

Use the query_ref clause to reference an existing Oracle CQL query by name.

You can reference a Oracle CQL query in the following Oracle CQL statements:

Prerequisites

The query must already exist (see Query).

Syntax

Figure 7-9 query_ref::=

query ref

Semantics

identifier

Specify the name of the query. This is the name you use to reference the query in subsequent Oracle CQL statements.

7.24 time_spec

Purpose

Use the time_spec clause to define a time duration in days, hours, minutes, seconds, milliseconds, or nanoseconds.

Default: if units are not specified, Oracle Event Processing assumes [second|seconds].

You can use the time_spec clause in the following Oracle CQL statements:

Prerequisites

None.

Syntax

Figure 7-10 time_spec::=

time spec

Figure 7-11 time_unit::=

time unit

Semantics

integer

Specify the number of time units.

time_unit

Specify the unit of time.

7.25 xml_attribute_list

Purpose

Use the xml_attribute_list clause to specify one or more XML attributes.

You can use the xml_attribute_list clause in the following Oracle CQL statements:

Prerequisites

If any stream elements are referenced, the stream must already exist.

Syntax

xml_attribute_list::=

xml attribute list

Semantics

xml_attr_list

Specify one or more XML attributes.

<query id="tkdata51_q1"><![CDATA[ 
    select XMLELEMENT(NAME "S0", XMLATTRIBUTES(tkdata51_S0.c1 as "C1", tkdata51_S0.c2 as "C2"), 
        XMLELEMENT(NAME "c1_plus_c2", c1+c2), XMLELEMENT(NAME "c2_plus_10", c2+10.0)) from tkdata51_S0 [range 1]
]]>
</query>

7.26 xml_attr_list

Purpose

Use the xml_attr_list clause to specify one or more XML attributes..

You can use the xml_attr_list clause in the following Oracle CQL statements:

Prerequisites

If any stream elements are referenced, the stream must already exist.

Syntax

xml_attr_list::=

xml attr list
arith expr

( arith_expr::=)

Semantics

xml_attr

Specify an XML attribute.

7.27 xqryargs_list

Purpose

Use the xqryargs_list clause to specify one or more arguments to an XML query.

You can use the non_mt_arg_list clause in the following Oracle CQL statements:

Prerequisites

If any stream elements are referenced, the stream must already exist.

Syntax

xqryargs_list::=

xqry args list
arith expr

( arith_expr::=)

Semantics

xqryarg

A clause that binds a stream element value to an XQuery variable or XPath operator.

You can bind any arithmetic expression that involves one or more stream elements (see arith_expr::=) to either a variable in a given XQuery or an XPath operator such as "." as a quoted string.