5 Expressions

This chapter provides a reference to expressions in Oracle Continuous Query Language (Oracle CQL). An expression is a combination of one or more values and one or more operations, including a constant having a definite value, a function that evaluates to a value, or an attribute containing a value.

Every expression maps to a data type. This simple expression evaluates to 4 and has data type NUMBER (the same data type as its components):

2*2 

The following expression is an example of a more complex expression that uses both functions and operators. The expression adds seven days to the current date, removes the time component from the sum, and converts the result to CHAR data type:

TO_CHAR(TRUNC(SYSDATE+7)) 

This chapter includes the following section:

5.1 Introduction to Expressions

Oracle Stream Explorer provides the following expressions:

You can use expressions in:

  • The select list of the SELECT statement

  • A condition of the WHERE clause and HAVING clause

Oracle Stream Explorer does not accept all forms of expressions in all parts of all Oracle CQL statements. Refer to the individual Oracle CQL statements in Oracle CQL Statements for information on restrictions on the expressions in that statement.

You must use appropriate expression notation whenever expr appears in conditions, Oracle CQL functions, or Oracle CQL statements in other parts of this reference. The sections that follow describe and provide examples of the various forms of expressions.

Note:

In stream input examples, lines beginning with h (such as h 3800) are heartbeat input tuples. These inform Oracle Stream Explorer that no further input will have a timestamp lesser than the heartbeat value.

5.2 aggr_distinct_expr

Use an aggr_distinct_expr aggregate expression when you want to use an aggregate built-in function with distinct. When you want to use an aggregate built-in function without distinct, see aggr_expr.

aggr_distinct_expr::=

img/GUID-8E6D17C4-2048-4399-A1AE-737A11F58891-default.png

(arith_expr::=)

You can specify an arith_distinct_expr as the argument of an aggregate expression.

You can use an aggr_distinct_expr in the following Oracle CQL statements:

For more information, see Built-In Aggregate Functions.

5.2.1 Examples

The following example shows how to use a COUNT aggregate distinct expression.

create view viewq2Cond1(ACCT_INTRL_ID, sumForeign, countForeign) as 
         select ACCT_INTRL_ID, sum(TRXN_BASE_AM), count(distinct ADDR_CNTRY_CD)
         from ValidCashForeignTxn[range 48 hours]
         group by ACCT_INTRL_ID 
         having ((sum(TRXN_BASE_AM) * 100) >= (1000 * 60) and
                 (count(distinct ADDR_CNTRY_CD >= 2)))

5.3 aggr_expr

Use an aggr_expr aggregate expression when you want to use aggregate built-in functions. When you want to use an aggregate built-in function with distinct, see aggr_distinct_expr.

aggr_expr::=

img/GUID-7B8FBC11-CCF5-49C0-899F-63A3173B5CB5-default.png

(arith_expr::= and xml_agg_expr::=)

You can specify an arith_expr as the argument of an aggregate expression.

The count aggregate built-in function takes a single argument made up of any of the values that Table 5-1 lists and returns the int value indicated.

Table 5-1 Return Values for COUNT Aggregate Function

Input Argument Return Value

arith_expr

The number of tuples where arith_expr is not null.

*

The number of tuples matching all the correlation variables in the pattern, including duplicates and nulls.

identifier.*

The number of all tuples that match the correlation variable identifier, including duplicates and nulls.

identifier.attr

The number of tuples that match correlation variable identifier, where attr is not null.

The first and last aggregate built-in functions take a single argument made up of the following period separated values:

  • identifier1: the name of a pattern as specified in a DEFINE clause.

  • identifier2: the name of a stream element as specified in a CREATE STREAM statement.

You can use an aggr_expr in the following Oracle CQL statements:

For more information, see:

5.3.1 Examples

The following example shows how to use a COUNT aggregate expression.

<view id="SegVol" schema="exp_way lane dir seg volume"><![CDATA[ 
    select 
        exp_way, 
        lane, 
        dir, 
        seg, 
        count(*) as volume 
    from 
        CurCarSeg 
    group by 
        exp_way,
        lane, 
        dir, 
        seg 
    having 
        count(*) > 50
]]></view>

5.4 arith_expr

Use an arith_expr arithmetic expression to define an arithmetic expression using any combination of stream element attribute values, constant values, the results of a function expression, aggregate built-in function, case expression, or decode. You can use all of the normal arithmetic operators (+,-,*, and /) and the concatenate operator (||).

arith_expr::=

5.4.1 Examples

The following example shows how to use an arith_expr expression.

<view id="SegVol" schema="exp_way lane dir seg volume"><![CDATA[ 
    select 
        exp_way, 
        speed * 1.5 as adjustedSpeed, 
        dir, 
        max(seg) as maxSeg, 
        count(*) as volume 
    from 
        CurCarSeg 
    having 
        adjustedSpeed > 50
]]></view>

5.5 arith_expr_list

Use an arith_expr_list arithmetic expression list to define one or more arithmetic expressions using any combination of stream element attribute values, constant values, the results of a function expression, aggregate built-in function, case expression, or decode. You can use all of the normal arithmetic operators (+,-,*, and /) and the concatenate operator (||).

arith_expr_list::=

img/GUID-D0BF860E-9B1F-4611-AE03-8B9770DAB88B-default.png

(arith_expr::=)

You can use an arith_expr_list in the following Oracle CQL statements:

For more information, see Arithmetic Operators.

5.5.1 Examples

The following example shows how to use a arith_expr_list expression.

<query id="q1"><![CDATA[ 
    select
        XMLELEMENT("Emp", XMLELEMENT("Name", e.job_id||' '||e.last_name),XMLELEMENT("Hiredate", e.hire_date)
        )
    from 
        tkdata51_S0 [range 1] as e
]]></query>

5.6 case_expr

Use a case_expr case expression to evaluate stream elements against multiple conditions.

case_expr::=

searched_case_list::=

searched_case::=

simple_case_list::=

simple_case::=

img/GUID-3F53A088-5623-4D73-8197-0535B749F9BA-default.png

(arith_expr::=)

The case_expr is similar to the DECODE clause of an arithmetic expression (see decode).

In a searched_case clause, when the non_mt_cond_list evaluates to true, the searched_case clause may return either an arithmetic expression or null.

In a simple_case clause, when the arithmetic expression is true, the simple_case clause may return either another arithmetic expression or null.

You can use a case_expr in the following Oracle CQL statements:

5.6.1 Examples

This section describes the following case_expr examples:

case_expr with SELECT *

Consider the query q97 and the data stream S0. Stream S1 has schema (c1 integer, c2 float). The query returns the relation.

<query id="q97"><![CDATA[ 
    select * from S0 
    where 
        case 
            when c2 < 25 then c2+5 
            when c2 > 25 then c2+10 
        end > 25
]]></query>
Timestamp   Tuple
     1000    0.1,10
     1002   0.14,15
   200000    0.2,20
   400000    0.3,30
   500000    0.3,35
   600000       ,35
h 800000
100000000   4.04,40
h 200000000
Timestamp   Tuple Kind  Tuple
400000:+ 0.3,30
500000:+ 0.3,35
600000:+ ,35
100000000:+ 4.04,40

case_expr with SELECT

Consider the query q96 and the data streams S0 and S1. Stream S0 has schema (c1 float, c2 integer) and stream S1 has schema (c1 float, c2 integer). The query returns the relation.

<query id="q96"><![CDATA[ 
    select 
        case to_float(S0.c2+10) 
            when (S1.c2*100)+10 then S0.c1+0.5 
            when (S1.c2*100)+11 then S0.c1 
            else S0.c1+0.3 
        end 
    from 
        S0[rows 100], 
        S1[rows 100]
]]></query>
Timestamp   Tuple
     1000    0.1,10
     1002   0.14,15
   200000    0.2,20
   400000    0.3,30
   500000    0.3,35
   600000       ,35
h 800000
100000000   4.04,40
h 200000000
Timestamp   Tuple
     1000   10,0.1
     1002   15,0.14
   200000   20,0.2
   300000     ,0.2
   400000   30,0.3
100000000   40,4.04
Timestamp   Tuple Kind  Tuple
     1000:  +           0.6
     1002:  +           0.44
     1002:  +           0.4
     1002:  +           0.14
   200000:  +           0.5
   200000:  +           0.5
   200000:  +           0.4
   200000:  +           0.44
   200000:  +           0.7
   300000:  +           0.4
   300000:  +           0.44
   300000:  +           0.7
   400000:  +           0.6
   400000:  +           0.6
   400000:  +           0.6
   400000:  +           0.6
   400000:  +           0.4
   400000:  +           0.44
   400000:  +           0.5
   400000:  +           0.8
   500000:  +           0.6
   500000:  +           0.6
   500000:  +           0.6
   500000:  +           0.6
   500000:  +           0.6
   600000:  +
   600000:  +
   600000:  +
   600000:  +
   600000:  +
100000000:  +           4.34
100000000:  +           4.34
100000000:  +           4.34
100000000:  +           4.34
100000000:  +           4.34
100000000:  +           0.4
100000000:  +           0.44
100000000:  +           0.5
100000000:  +           0.6
100000000:  +           0.6
100000000:  +
100000000:  +           4.34

5.7 decode

Use a decode expression to evaluate stream elements against multiple conditions.

decode::=

img/GUID-9794B49C-1B65-45FC-B786-30434412E7A6-default.png
expr, search1, result1, search2, result2, ... , searchN, result N, default

DECODE compares expr to each search value one by one. If expr equals a search value, the DECODE expressions returns the corresponding result. If no match is found, the DECODE expressions returns default. If default is omitted, the DECODE expressions returns null.

The arguments can be any of the numeric (INTEGER, BIGINT, FLOAT, or DOUBLE) or character (CHAR) data types. For more information, see Data Types).

The search, result, and default values can be derived from expressions. Oracle Stream Explorer uses short-circuit evaluation. It evaluates each search value only before comparing it to expr, rather than evaluating all search values before comparing any of them with expr. Consequently, Oracle Stream Explorer never evaluates a search i, if a previous search j (0 < j < i) equals expr.

Oracle Stream Explorer automatically converts expr and each search value to the data type of the first search value before comparing. Oracle Stream Explorer automatically converts the return value to the same data type as the first result.

In a DECODE expression, Oracle Stream Explorer considers two nulls to be equivalent. If expr is null, then Oracle Stream Explorer returns the result of the first search that is also null.

The maximum number of components in the DECODE expression, including expr, searches, results, and default, is 255.

The decode expression is similar to the case_expr (see case_expr::=).

You can use a decode expression in the following Oracle CQL statements:

5.7.1 Examples

Consider the query q and the input relation R. Relation R has schema (c1 float, c2 integer). The query returns the relation.

<query id="q"><![CDATA[ 
...
    SELECT DECODE (c2, 10, c1+0.5, 20, c1+0.1, 30, c1+0.2, c1+0.3) from R
]]></query>
Timestamp   Tuple Kind  Tuple
     1000:    +    0.1,10
     1002:    +    0.14,15
     2000:    -    0.1,10
     2002:    -    0.14,15
   200000:    +    0.2,20
   201000:    -    0.2,20
   400000:    +    0.3,30
   401000:    -    0.3,30
   500000:    +    0.3,35
   501000:    -    0.3,35
   600000:    +    0.3,35
   601000:    -    0.3,35
100000000:    +    4.04,40
100001000:    -    4.04,40
Timestamp   Tuple Kind  Tuple
   1000:    +    0.6
   1002:    +    0.44
   2000:    -    0.1,10
   2002:    -    0.14,15
 200000:    +    0.3
 201000:    -    0.2,20
 400000:    +    0.5
 401000:    -    0.3,30
 500000:    +    0.6
 501000:    -    0.3,35
100000000:  +    4.34
100001000:  -    4.34

5.8 func_expr

Use the func_expr function expression to define a function invocation using any Oracle CQL built-in, user-defined, or Oracle data cartridge function.

func_expr::=

img/GUID-775B5CDA-C457-4978-B737-BDC0D0E1FCC3-default.png

func_name

You can specify the identifier of a function explicitly:

PREV

The PREV function takes a single argument made up of the following period-separated identifier arguments:

  • identifier1: the name of a pattern as specified in a DEFINE clause.

  • identifier2: the name of a stream element as specified in a CREATE STREAM statement.

The PREV function also takes the following const_int arguments:

  • const_int: the index of the stream element before the current stream element to compare against. Default: 1.

  • const_bigint: the timestamp of the stream element before the current stream element to compare against. To obtain the timestamp of a stream element, you can use the ELEMENT_TIME pseudocolumn (see ELEMENT_TIME Pseudocolumn).

For more information, see prev. For an example, see func_expr PREV Function Example.

XQuery: XMLEXISTS and XMLQUERY

You can specify an XQuery that Oracle Event Processing applies to the XML stream element data that you bind in xqryargs_list. For more information, see:

An xqryargs_list is a comma separated list of one or more xqryarg instances made up of an arithmetic expression involving one or more stream elements from the select list, the AS keyword, and a const_string that represents the XQuery variable or operator (such as the "." current node operator).

For an example, see func_expr XMLQUERY Function Example.

For more information, see SQL/XML (SQLX).

XMLCONCAT

The XMLCONCAT function returns the concatenation of its comma-delimited xmltype arguments as an xmltype.

For more information, see:

SQL/XML (SQLX)

The SQLX specification extends SQL to support XML data.

Oracle CQL supports event types containing properties of type SQLX. In this case, Oracle Event Processing server converts from SQLX to String when within Oracle CQL, and converts from String to SQLX on output.

Oracle CQL provides the following expressions (and functions) to manipulate data from an SQLX stream. For example, you can construct XML elements or attributes with SQLX stream elements, combine XML fragments into larger ones, and parse input into XML content or documents.

Note:

Oracle CQL does not support external relations with columns of type XMLTYPE (for example, a join with a relational database management system). For more information, see Oracle CQL Built-in Data Types.

For more information on Oracle CQL SQLX expressions, see:

For more information on Oracle CQL SQLX functions, see:

For more information on data type restrictions when using Oracle CQL with XML, see:

For more information, see .

FIRST and LAST

The FIRST and LAST functions each take a single argument made up of the following period-separated values:

  • identifier1: the name of a pattern as specified in a DEFINE clause.

  • identifier2: the name of a stream element as specified in a CREATE STREAM statement.

For more information, see:

You can specify the identifier of a function explicitly with or without a non_mt_arg_list: a list of arguments appropriate for the built-in or user-defined function being invoked. The list can have single or multiple arguments.

You can use a func_expr in the following Oracle CQL statements:

For more information, see Functions.

5.8.1 Examples

This section describes the following func_expr examples:

func_expr PREV Function Example

The following example shows how to compose a func_expr to invoke the PREV function.

<query id="q36"><![CDATA[ 
    select T.Ac1 from S15 
    MATCH_RECOGNIZE ( 
        PARTITION BY
            c2 
        MEASURES 
            A.c1 as Ac1 
        PATTERN(A) 
        DEFINE 
            A as (A.c1 = PREV(A.c1,3,5000) )
    ) as T
]]></query>

func_expr XMLQUERY Function Example

The following example shows how to compose a func_expr to invoke the XMLQUERY function.

<query id="q1"><![CDATA[ 
    select
        xmlexists(
            "for $i in /PDRecord where $i/PDId <= $x return $i/PDName" 
            passing by value 
                c2 as ".", 
                (c1+1) as "x" 
            returning content
        ) xmldata
    from
        S1
]]></query>

The following example shows how to compose a func_expr to invoke the SUM function.

<query id="q3"><![CDATA[ 
    select sum(c2) from S1[range 5]
]]></query>

5.9 object_expr

Use the object_expr expression to reference the members of a data cartridge complex type.

You can use an object_expr anywhere an arithmetic expression can be used. For more information, see arith_expr.

object_expr::=

img/GUID-358E5B85-50E0-4978-9D7E-B4C8C6D74255-default.png
img/GUID-BE6BDCFA-8E4E-4F39-8F51-5D6E9B6A154F-default.png

external_qualified_identifier::=

img/GUID-3A798DD3-BA27-4F8D-86A0-69B4AB1287E3-default.png

()

external_identifier::=

img/GUID-FE5C15E2-8514-477A-958A-7B7A1085F62F-default.png

nested_method_field_expr::=

img/GUID-CA4BD351-5C34-4779-A5DC-B589C9146CA6-default.png

array_expr::=

img/GUID-C4AD497B-DEDC-4B1B-8F66-3A892F9DB999-default.png

method_expr::=

img/GUID-8238C1D1-EAB2-4E87-B208-2954C95613BD-default.png

Optionally, you can use a link (@) in the object_expr to specify the data cartridge name. Use a link to specify the location of an Oracle CQL data cartridge complex type class, method, field, or constructor to disambiguate the reference, if necessary. The location must reference a data cartridge by its name. For example, if two data cartridges (myCartridge and yourCartridge) both define a complex type com.package.ThisClass, then you must use the link clause to explicitly identify which com.package.ThisClass you want to use.

Note:

A link is not required when using the types that the default Java data cartridge provides.

link::=

img/GUID-62514002-787B-412E-A7F7-BF0FF704C769-default.png
img/GUID-5F5976AD-4645-4A06-8FF1-F7CA6BD008B8-default.png

data_cartridge_name

Each Oracle CQL data cartridge implementation is identified by a unique data cartridge name.

Data cartridge names include:

  • java: identifies the Oracle CQL Java data cartridge.

    This is the default data cartridge name. If you omit a data cartridge name in field or constructor references, Oracle CQL will try to resolve the reference using the java data cartridge name. This means the following statements are identical:

    SELECT java.lang.String@java(“foo") …
    SELECT java.lang.String(“foo") …
    

    If you omit a data cartridge name in a method reference, Oracle CQL will try to resolve the reference against its built-in functions (see Functions).

  • spatial: identifies the Oracle CQL Oracle Spatial.

For syntax, see ::= (parent: link::=).

Type Declaration

You declare an event property as a complex type using qualified_type_name@data_cartridge_name.

For examples, see Type Declaration Example: link

Field Access

You cannot specify a link when accessing a complex type field because the type of the field already identifies its location. The following is not allowed:

SELECT java.lang.String(“foo").CASE_INSENSITIVE_ORDER@java …

For examples, see Field Access Example: link.

Method Access

You cannot specify a link when accessing complex type method because the type of the method already identifies its location. The following is not allowed:

SELECT java.lang.String(“foo").substring@java(0,1) …

For examples, see Method Access Example: link.

Constructor Invocation

You invoke a complex type constructor using qualified_type_name@data_cartridge_name(param_list).

For examples, see Constructor Invocation Example: link.

5.9.1 Examples

The following examples illustrate the various semantics that this statement supports:

Object Expression Example

The following example shows object_expr:

getContainingGeometries@spatial (InputPoints.point)

This object_expr uses a data cartridge TABLE clause that invokes the Oracle Spatial method getContainingGeometries, passing in one parameter (InputPoints.point). The return value of this method, a Collection of Oracle Stream Explorer IType records, is aliased as validGeometries. The table source itself is aliased as R2.

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

Type Declaration Example: link

The following example shows how to create an event type as a Java class that specifies an event property as an Oracle CQL data cartridge complex type MyType defined in package com.mypackage that belongs to the Oracle CQL data cartridge myCartridge. If a com.myPackage.MyType is defined in some other Oracle CQL data cartridge (with data cartridge name otherCatridge), specifying the type for the a1 property using a link with the data cartridge name myCartridge allows Oracle CQL to reference the correct complex type.

package com.myapplication.event;

import java.util.Date;
import // Oracle CQL data cartridge package(s)?

public final class MarketEvent {
    private final String symbol;
    private final Double price;
    private final com.myPackage.MyType@myCartridge a1;

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

Field Access Example: link

The following example shows how to instantiate complex type MyType and access the static field MY_FIELD. The link clause explicitly references the com.myPackage.MyType class that belongs to the Oracle CQL data cartridge myCartridge.

<query id="q1"><![CDATA[ 
    SELECT com.myPackage.MyType@myCartridge(“foo").MY_FIELD ...
]]></query>

Method Access Example: link

The following example shows how to instantiate complex type MyType and access the method myMethod. The link clause explicitly references the com.myPackage.MyType class that belongs to the Oracle CQL data cartridge myCartridge.

<query id="q1"><![CDATA[ 
    SELECT com.myPackage.MyType@myCartridge(“foo").myMethod("bar") ...
]]></query>

Constructor Invocation Example: link

The following example shows how to instantiate complex type MyType. The link clause explicitly references the com.myPackage.MyType class that belongs to the Oracle CQL data cartridge myCartridge.

<query id="q1"><![CDATA[ 
    SELECT com.myPackage.MyType@myCartridge(“foo") ...
]]></query>

5.10 order_expr

Use the order_expr expression to specify the sort order in which Oracle Stream Explorer returns tuples that a query selects.

order_expr::=

img/GUID-D69E5B49-2AA0-4D97-8065-176EB1EEBA56-default.png

You can specify a stream element by attr name.

Alternatively, you can specify a stream element by its const_int index where the index corresponds to the stream element position you specify at the time you register or create the stream.

5.10.1 Examples

Stream S3 has schema (c1 bigint, c2 interval, c3 byte(10), c4 float). This example shows how to order the results of query q210 by c1 and then c2 and how to order the results of query q211 by c2, then by the stream element at index 3 (c3) and then by the stream element at index 4 (c4).

<query id="q210"><![CDATA[ 
    select * from S3 order by c1 desc nulls first, c2 desc nulls last
]]></query>
<query id="q211"><![CDATA[ 
    select * from S3 order by c2 desc nulls first, 3 desc nulls last, 4 desc
]]></query>

5.11 xml_agg_expr

Use an xml_agg_expr expression to return a collection of XML fragments as an aggregated XML document. Arguments that return null are dropped from the result.

xml_agg_expr::=

img/GUID-0F9B91E6-1CA8-4CC5-9C7F-B4C1F3936923-default.png

(arith_expr)

You can specify an xml_agg_expr as the argument of an aggregate expression.

You can use an xml_agg_expr in the following Oracle CQL statements:

For more information, see:

5.11.1 Examples

Consider the query tkdata67_q1 and the input relation tkdata67_S0. Relation tkdata67_S0 has schema (c1 integer, c2 float). The query returns the relation.

<query id="tkdata67_q1"><![CDATA[ 
    select 
        c1, 
        xmlagg(xmlelement("c2",c2)) 
    from 
        tkdata67_S0[rows 10] 
    group by c1
]]></query>
Timestamp           Tuple
 1000               15, 0.1
 1000               20, 0.14
 1000               15, 0.2
 4000               20, 0.3
10000               15, 0.04
h 12000
Timestamp   Tuple Kind  Tuple
1000:       +           15,<c2>0.1</c2>
                           <c2>0.2</c2>
1000:       +           20,<c2>0.14</c2>
4000:       -           20,<c2>0.14</c2>
4000:       +           20,<c2>0.14</c2>
                           <c2>0.3</c2>
10000:      -           15,<c2>0.1</c2>
                           <c2>0.2</c2>
10000:      +           15,<c2>0.1</c2>
                           <c2>0.2</c2>
                           <c2>0.04</c2>

5.12 xmlcolattval_expr

Use an xmlcolattval_expr expression to create an XML fragment and then expand the resulting XML so that each XML fragment has the name column with the attribute name.

xmlcolattval_expr::=

img/GUID-AB9D6C21-6495-4CBB-B7B6-1BF696F40598-default.png

You can specify an xmlcolattval_expr as the argument of a function expression. It is especially useful when processing SQLX streams. For more information, see SQL/XML (SQLX).

You can use an xmlcolattval_expr in the following Oracle CQL statements:

For more information, see .

5.12.1 Examples

Consider the query tkdata53_q1 and the input relation tkdata53_S0. Relation tkdata53_S0 has schema (c1 integer, c2 float). The query returns the relation.

<query id="tkdata53_q1"><![CDATA[ 
    select 
        XMLELEMENT("tkdata53_S0", XMLCOLATTVAL( tkdata53_S0.c1, tkdata53_S0.c2)) 
    from 
        tkdata53_S0 [range 1]
]]></query>
Timestamp                Tuple
     1000:               10, 0.1
     1002:               15, 0.14
   200000:               20, 0.2
   400000:               30, 0.3
h 800000
100000000:               40, 4.04
h 200000000
Timestamp   Tuple Kind  Tuple
     1000:       +      <tkdata53_S0>
                            <column name="c1">10</column>
                            <column name="c2">0.1</column>
                        </tkdata53_S0>
     1002:       +      <tkdata53_S0>
                            <column name="c1">15</column>
                            <column name="c2">0.14</column>
                        </tkdata53_S0>
     2000:       -      <tkdata53_S0>
                            <column name="c1">10</column>
                            <column name="c2">0.1</column>
                        </tkdata53_S0>
     2002:       -      <tkdata53_S0>
                            <column name="c1">15</column>
                            <column name="c2">0.14</column>
                        </tkdata53_S0>
   200000:       +      <tkdata53_S0>
                            <column name="c1">20</column>
                            <column name="c2">0.2</column>
                        </tkdata53_S0>
   201000:       -      <tkdata53_S0>
                            <column name="c1">20</column>
                            <column name="c2">0.2</column>
                        </tkdata53_S0>
   400000:       +      <tkdata53_S0>
                            <column name="c1">30</column>
                            <column name="c2">0.3</column>
                        </tkdata53_S0>
   401000:       -      <tkdata53_S0>
                            <column name="c1">30</column>
                            <column name="c2">0.3</column>
                        </tkdata53_S0>
100000000:       +      <tkdata53_S0>
                            <column name="c1">40</column>
                            <column name="c2">4.04</column>
                        </tkdata53_S0>
100001000:       -      <tkdata53_S0>
                            <column name="c1">40</column>
                            <column name="c2">4.04</column>
                        </tkdata53_S0>

5.13 xmlelement_expr

Use an xmlelement_expr expression when you want to construct a well-formed XML element from stream elements.

xmlelement_expr::=

img/GUID-5165D068-E501-445B-9BE3-6F95F781C6F7-default.png

(arith_expr::= and arith_expr_list::=)

You can specify an xmlelement_expr as the argument of a function expression. It is especially useful when processing SQLX streams. For more information, see "SQL/XML (SQLX)".

You can use an xmlelement_expr in the following Oracle CQL statements:

For more information, see .

5.13.1 Examples

Consider the query tkdata51_q0 and the input relation tkdata51_S0. Relation tkdata51_S0 has schema (c1 integer, c2 float). The query returns the relation.

<query id="tkdata51_q0"><![CDATA[ 
    select 
        XMLELEMENT(
            NAME "S0", 
            XMLELEMENT(NAME "c1", tkdata51_S0.c1), 
            XMLELEMENT(NAME "c2", tkdata51_S0.c2)
        ) 
    from 
        tkdata51_S0 [range 1]
]]></query>
Timestamp                Tuple
     1000:               10, 0.1
     1002:               15, 0.14
   200000:               20, 0.2
   400000:               30, 0.3
h 800000
100000000:               40, 4.04
h 200000000
Timestamp   Tuple Kind  Tuple
     1000:  +           <S0>
                            <c1>10</c1>
                            <c2>0.1</c2>
                        </S0>
     1002:  +           <S0>
                            <c1>15</c1>
                            <c2>0.14</c2>
                        </S0>
     2000:  -           <S0>
                            <c1>10</c1>
                            <c2>0.1</c2>
                        </S0>
     2002:  -           <S0>
                            <c1>15</c1>
                            <c2>0.14</c2>
                        </S0>
   200000:  +           <S0>
                            <c1>20</c1>
                            <c2>0.2</c2>
                        </S0>
   201000:  -           <S0>
                            <c1>20</c1>
                            <c2>0.2</c2>
                        </S0>
   400000:  +           <S0>
                            <c1>30</c1>
                            <c2>0.3</c2>
                        </S0>
   401000:  -           <S0>
                            <c1>30</c1>
                            <c2>0.3</c2>
                        </S0>
100000000:  +           <S0>
                            <c1>40</c1>
                            <c2>4.04</c2>
                        </S0>
100001000:  -           <S0>
                            <c1>40</c1>
                            <c2>4.04</c2>
                        </S0>

5.14 xmlforest_expr

Use an xmlforest_expr to convert each of its argument parameters to XML, and then return an XML fragment that is the concatenation of these converted arguments.

xmlforest_expr::=

img/GUID-0D9D797C-6785-4A9B-AAF8-B15B8C08EC39-default.png

You can specify an xmlforest_expr as the argument of a function expression. It is especially useful when processing SQLX streams. For more information, see SQL/XML (SQLX).

You can use an xmlforest_expr in the following Oracle CQL statements:

For more information, see .

5.14.1 Examples

Consider the query tkdata52_q0and the input relation tkdata52_S0. Relation tkdata52_S0 has schema (c1 integer, c2 float). The query returns the relation.

<query id="tkdata52_q0"><![CDATA[ 
    select 
        XMLFOREST( tkdata52_S0.c1, tkdata52_S0.c2) 
    from 
        tkdata52_S0 [range 1]
]]></query>
Timestamp                Tuple
     1000:               10, 0.1
     1002:               15, 0.14
   200000:               20, 0.2
   400000:               30, 0.3
h 800000
100000000:               40, 4.04
h 200000000
Timestamp   Tuple Kind  Tuple
     1000:  +           <c1>10</c1>
                        <c2>0.1</c2>
     1002:  +           <c1>15</c1>
                        <c2>0.14</c2>
     2000:  -           <c1>10</c1>
                        <c2>0.1</c2>
     2002:  -           <c1>15</c1>
                        <c2>0.14</c2>
   200000:  +           <c1>20</c1>
                        <c2>0.2</c2>
   201000:  -           <c1>20</c1>
                        <c2>0.2</c2>
   400000:  +           <c1>30</c1>
                        <c2>0.3</c2>
   401000:  -           <c1>30</c1>
                        <c2>0.3</c2>
100000000:  +           <c1>40</c1>
                        <c2>4.04</c2>
100001000:  -           <c1>40</c1>
                        <c2>4.04</c2>

5.15 xml_parse_expr

Use an xml_parse_expr expression to parse and generate an XML instance from the evaluated result of arith_expr.

xml_parse_expr::=

img/GUID-1A475585-BB8C-4690-9429-8D240A61A28E-default.png

(arith_expr::=)

When using an xml_parse_expr expression, note the following:

  • If arith_expr resolves to null, then the expression returns null.

  • If you specify content, then arith_expr must resolve to a valid XML value. For an example, see xml_parse_expr Document Example

  • If you specify document, then arith_expr must resolve to a singly rooted XML document. For an example, see xml_parse_expr Content Example.

  • When you specify wellformed, you are guaranteeing that value_expr resolves to a well-formed XML document, so the database does not perform validity checks to ensure that the input is well formed. For an example, see xml_parse_expr Wellformed Example.

You can specify an xml_parse_expr as the argument of a function expression. It is especially useful when processing SQLX streams. For more information, see SQL/XML (SQLX).

You can use an xml_parse_expr in the following Oracle CQL statements:

For more information, see .

5.15.1 Examples

This section describes the following xml_parse_expr examples:

xml_parse_expr Content Example

Consider the query tkdata62_q3 and the input relation tkdata62_S1. Relation tkdata62_S1 has schema (c1 char(30)). The query returns the relation.

<query id="tkdata62_q3"><![CDATA[ 
    select XMLPARSE(CONTENT c1) from tkdata62_S1
]]></query>
Timestamp               Tuple
1000                    "<a>3</a>"
1000                    "<e3>blaaaaa</e3>"
1000                    "<r>4</r>"
1000                    "<a></a>
1003                    "<a>s3</a>"
1004                    "<d>b6</d>"
Timestamp   Tuple Kind  Tuple
1000:       +     <a>3</a>
1000:       +     <e3>blaaaaa</e3>
1000:       +     <r>4</r>
1000:       +     <a/>
1003:       +     <a>s3</a>
1004:       +     <d>b6</d>

xml_parse_expr Document Example

Consider the query tkdata62_q4 and the input relation tkdata62_S1. Relation tkdata62_S1 has schema (c1 char(30)). The query returns the relation.

<query id="tkdata62_q4"><![CDATA[ 
    select XMLPARSE(DOCUMENT c1) from tkdata62_S1
]]></query>
Timestamp               Tuple
1000                    "<a>3</a>"
1000                    "<e3>blaaaaa</e3>"
1000                    "<r>4</r>"
1000                    "<a></a>
1003                    "<a>s3</a>"
1004                    "<d>b6</d>"
Timestamp   Tuple Kind  Tuple
1000:       +     <a>3</a>
1000:       +     <e3>blaaaaa</e3>
1000:       +     <r>4</r>
1000:       +     <a/>
1003:       +     <a>s3</a>
1004:       +     <d>b6</d>

xml_parse_expr Wellformed Example

Consider the query tkdata62_q2 and the input relation tkdata62_S. Relation tkdata62_S has schema (c char(30)). The query returns the relation.

<query id="tkdata62_q2"><![CDATA[ 
    select XMLPARSE(DOCUMENT c WELLFORMED) from tkdata62_S
]]></query>
Timestamp               Tuple
1000                    "<a>3</a>"
1000                    "<e3>blaaaaa</e3>"
1000                    "<r>4</r>"
1000                    "<a/>"
1003                    "<a>s3</a>"
1004                    "<d>b6</d>"
Timestamp   Tuple Kind  Tuple
1000:       +           <a>3</a>
1000:       +           <e3>blaaaaa</e3>
1000:       +           <r>4</r>
1000:       +           <a/>
1003:       +           <a>s3</a>
1004:       +           <d>b6</d>