The MULTISET operators combine two collections to form a third collection.
Syntax
Where coll_1 and coll_2 specify the names of the collections to combine.
Include the ALL keyword to specify to represent duplicate elements (elements that are present in both coll_1 and coll_2) in the result, once for each time they're present in the original collections. This is the default behavior.
Include the DISTINCT or UNIQUE keyword to include duplicate elements in the result only once. There is no difference between the DISTINCT and UNIQUE keywords.
There are three forms of MULTISET operators:
MULTISET UNION
MULTISET INTERSECT
MULTISET EXCEPT
MULTISET UNION
MULTISET UNION takes as arguments two nested tables and returns a nested table whose values from both the input nested tables. The two input nested tables must be of the same type, and the returned nested table is of the same type as well.
This example uses the MULTISET UNION operator to combine collection_1 and collection_2 into a third collection, collection_3:
The resulting collection includes one entry for each element in collection_1 and collection_2. If you use the DISTINCT keyword, the results are as follows:
The resulting collection includes only those members with distinct values.
In this example, the MULTISET UNION DISTINCT operator removes duplicate entries that are stored in the same collection:
MULTISET INTERSECT
MULTISET INTERSECT takes as arguments two nested tables and returns a nested table whose values are common in the two input nested tables. The two input nested tables must be of the same type, and the returned nested table is of the same type as well.
This example uses the MULTISET INTERSECT operator to combine color_name and fruit_name into a third collection, common_name:
This example shows the use of MULTISET INTERSECT DISTINCT:
This example shows the use of MULTISET INTERSECT ALL:
MULTISET EXCEPT
MULTISET EXCEPT takes two nested tables as arguments and returns a nested table whose elements are in the first nested table but not in the second nested table. The two input nested tables must be of the same type, and the returned nested table is of the same type as well.
This example shows the use of MULTISET EXCEPT UNIQUE:
This example shows the use of MULTISET EXCEPT DISTINCT:
This example shows the use of MULTISET EXCEPT ALL: