Handling Other Datatypes Using Oracle CQL Data Cartridges Handling Other Datatypes Using a User-Defined Function

2-4 Oracle Complex Event Processing CQL Language Reference OPEN1, CLOSED0} } Example 2–2 Event Using Enum Datatype ProcessStatus package com.oracle.app; import com.oracle.capp.ProcessStatus; public class ServiceOrder { private String serviceOrderId; private String electronicSerialNumber; private ProcessStatus status; ... } By creating the user-defined function that Example 2–3 shows and registering the function in your application assembly file as Example 2–4 shows, you can evaluate this enum datatype in an Oracle CQL query as Example 2–5 shows. Example 2–3 User-Defined Function to Evaluate Enum Datatype package com.oracle.app; import com.oracle.capp.ProcessStatus; public class CheckIfStatusClosed { public boolean executeObject[] args { ProcessStatus arg0 = ProcessStatusargs[0]; if arg0 == ProcessStatus.OPEN return Boolean.FALSE; else return Boolean.TRUE; } } Example 2–4 Registering the User-Defined Function in Application Assembly File wlevs:processor id=testProcessor wlevs:listener ref=providerCache wlevs:listener ref=outputCache wlevs:cache-source ref=testCache wlevs:function function-name=statusClosed exec-method=”execute” bean class=com.oracle.app.CheckIfStatusClosed wlevs:function wlevs:processor Example 2–5 Using the User-Defined Function to Evaluate Enum Datatype in an Oracle CQL Query query id=rule-04[CDATA[ SELECT meter.electronicSerialNumber, meter.exceptionKind FROM MeterLogEvent AS meter, ServiceOrder AS svco WHERE meter.electronicSerialNumber = svco.electronicSerialNumber and svco.serviceOrderId IS NULL OR statusClosedsvco.status ]]query For more information, see Chapter 13, User-Defined Functions . Basic Elements of Oracle CQL 2-5

2.3 Datatype Comparison Rules

This section describes how Oracle CEP compares values of each datatype.

2.3.1 Numeric Values

A larger value is considered greater than a smaller one. All negative numbers are less than zero and all positive numbers. Thus, -1 is less than 100; -100 is less than -1.

2.3.2 Date Values

A later date is considered greater than an earlier one. For example, the date equivalent of 29-MAR-2005 is less than that of 05-JAN-2006 and 05-JAN-2006 1:35pm is greater than 05-JAN-2005 10:09am.

2.3.3 Character Values

Oracle CQL supports Lexicographic sort based on dictionary order. Internally, Oracle CQL compares the numeric value of the char. Depending on the encoding used, the numeric values will differ, but in general, the comparison will remain the same. For example: ’a’ ’b’ ’aa’ ’ab’ ’aaaa’ ’aaaab’

2.3.4 Datatype Conversion

Generally an expression cannot contain values of different datatypes. For example, an arithmetic expression cannot multiply 5 by 10 and then add JAMES. However, Oracle CEP supports both implicit and explicit conversion of values from one datatype to another. Oracle recommends that you specify explicit conversions, rather than rely on implicit or automatic conversions, for these reasons: ■ Oracle CQL statements are easier to understand when you use explicit datatype conversion functions. ■ Implicit datatype conversion can have a negative impact on performance. ■ Implicit conversion depends on the context in which it occurs and may not work the same way in every case. ■ Algorithms for implicit conversion are subject to change across software releases and among Oracle products. Behavior of explicit conversions is more predictable. This section describes: ■ Section 2.3.4.1, Implicit Datatype Conversion ■ Section 2.3.4.2, Explicit Datatype Conversion ■ Section 2.3.4.3, SQL Datatype Conversion ■ Section 2.3.4.4, Oracle Data Cartridge Datatype Conversion ■ Section 2.3.4.5, User-Defined Function Datatype Conversion 2-6 Oracle Complex Event Processing CQL Language Reference

2.3.4.1 Implicit Datatype Conversion

Oracle CEP automatically converts a value from one datatype to another when such a conversion makes sense. Table 2–2 is a matrix of Oracle implicit conversions. The table shows all possible conversions marked with an X. Unsupported conversions are marked with a --. The following rules govern the direction in which Oracle CEP makes implicit datatype conversions: ■ During SELECT FROM operations, Oracle CEP converts the data from the stream to the type of the target variable if the select clause contains arithmetic expressions or condition evaluations. For example, implicit conversions occurs in the context of expression evaluation, such as c1+2.0, or condition evaluation, such as c1 2.0, where c1 is of type INTEGER. ■ Conversions from FLOAT to BIGINT are exact. ■ Conversions from BIGINT to FLOAT are inexact if the BIGINT value uses more bits of precision that supported by the FLOAT. ■ When comparing a character value with a TIMESTAMP value, Oracle CEP converts the character data to TIMESTAMP. ■ When you use a Oracle CQL function or operator with an argument of a datatype other than the one it accepts, Oracle CEP converts the argument to the accepted datatype wherever supported. ■ When making assignments, Oracle CEP converts the value on the right side of the equal sign = to the datatype of the target of the assignment on the left side. ■ During concatenation operations, Oracle CEP converts from noncharacter datatypes to CHAR. ■ During arithmetic operations on and comparisons between character and noncharacter datatypes, Oracle CEP converts from numeric types to CHAR as Table 2–2 shows. Table 2–2 Implicit Type Conversion Matrix to CHA R to BYT E to BOOL EAN to INT E GER to DOUBL E to BIGINT to FL O A T to TIMEST AMP to INT E R V A L from CHAR -- -- -- -- -- -- -- X -- from BYTE X -- -- -- -- -- -- -- -- from BOOLEAN -- -- X -- -- -- -- -- -- from INTEGER X -- -- -- X X X -- -- from DOUBLE X -- -- -- X -- -- -- -- from BIGINT X -- -- -- X -- X -- -- from FLOAT X -- -- -- X -- -- -- -- from TIMESTAMP X -- -- -- -- -- -- -- -- from INTERVAL X -- -- -- -- -- -- -- --