Null Conditions Compound Conditions

Conditions 6-9

6.8 IN Condition

You can use the IN and NOT IN condition in the following ways: ■ in_condition_set : Section 6.8.1, Using IN and NOT IN as a Set Operation ■ in_condition_membership : Section 6.8.2, Using IN and NOT IN as a Membership Condition When using the NOT IN condition, be aware of the effect of null values as Section 6.8.3, NOT IN and Null Values describes.

6.8.1 Using IN and NOT IN as a Set Operation

See BINARY Example: IN and NOT IN on page 20-17.

6.8.2 Using IN and NOT IN as a Membership Condition

In this usage, the query will be a SELECT-FROM-WHERE query that either tests whether or not one argument is a member of a list of arguments of the same type or tests whether or not a list of arguments is a member of a set of similar lists. in_condition_membership::= arith_expr::= on page 5-6, non_mt_arg_list::= on page 7-20, non_mt_arg_list_set::= on page 6-9 non_mt_arg_list_set::= non_mt_arg_list::= on page 7-20 When you use IN or NOT IN to test whether or not a non_mt_arg_list is a member of a set of similar lists, then you must use a non_mt_arg_list_set. Each non_mt_ arg_list in the non_mt_arg_list_set must match the non_mt_arg_list to the left of the condition in number and type of arguments. Consider the query Q1 in Example 6–1 and the data stream S0 in Example 6–2 . Stream S0 has schema c1 integer, c2 integer. Example 6–3 shows the relation that See Also: Section 6.3, Logical Conditions for more information about NOT, AND, and OR conditions Note: You cannot combine these two usages. Note: You cannot combine this usage with in_condition_set as Section 6.8.1, Using IN and NOT IN as a Set Operation describes. 6-10 Oracle Complex Event Processing CQL Language Reference the query returns. In Q1, the non_mt_arg_list_set is 50,4,4,5. Note that each non_mt_arg_list that it contains matches the number and type of arguments in the non_mt_arg_list to the left of the condition, c1, c2. Example 6–1 S [range C on E] INTERVAL Value: Query query id=Q1[CDATA[ select c1,c2 from S0[range 1] where c1,c2 in 50,4,4,5 ]]query Example 6–2 S [range C on E] INTERVAL Value: Stream Input Timestamp Tuple 1000 50, 4 2000 30, 6 3000 , 5 4000 22, h 200000000 Example 6–3 S [range C on E] INTERVAL Value: Relation Output Timestamp Tuple Kind Tuple 1000: + 50,4 2000: - 50,4

6.8.3 NOT IN and Null Values

If any item in the list following a NOT IN operation evaluates to null, then all stream elements evaluate to FALSE or UNKNOWN, and no rows are returned. For example, the following statement returns c1 and c2 if c1 is neither 50 nor 30: query id=check_notin1[CDATA[ select c1,c2 from S0[range 1] where c1 not in 50, 30 ]]query However, the following statement returns no stream elements: query id=check_notin1[CDATA[ select c1,c2 from S0[range 1] where c1 not in 50, 30, NULL ]]query The preceding example returns no stream elements because the WHERE clause condition evaluates to: c1 = 50 AND c1 = 30 AND c1 = null Because the third condition compares c1 with a null, it results in an UNKNOWN, so the entire expression results in FALSE for stream elements with c1 equal to 50 or 30. This behavior can easily be overlooked, especially when the NOT IN operator references a view. Moreover, if a NOT IN condition references a view that returns no stream elements at all, then all stream elements will be returned, as shown in the following example. Since V1 returns no stream elements at all, Q1 will return view id=V1 schema=c1[CDATA[ IStreamselect from S1[range 10 slide 10] where 1=2 ]]view view id=V2 schema=c1[CDATA[ IStreamselect from S1[range 10 slide 10] where c1=2