Collections can be combined with SQL. Create collections, convert collections to tables, join tables, and then convert them back to collection.
This can be tricky the first time you encounter this stream of logic in an external linear representation. Especially with advanced features such as object types, cross-connects, and cast / collect. The steps are numbered and numbered to help you keep track. The advantage of constructing a query in this way is that it is much easier to debug. Start in the middle, select and run the request block in your IDE and continue moving until you understand the entire request.
--#4: Create new collection of results. select cast(collect(obj_test(id, val)) as obj_test_list) from ( --#3: Join lists and add results - returns results in normalized format. select coalesce(list_1_normalized.id, list_2_normalized.id) id, coalesce(list_1_normalized.val, 0) + coalesce(list_2_normalized.val, 0) val from ( --#2a: List 1 normalized. select id, val from ( --#1a: List 1 objects. select obj_test_list(obj_test(1,100),obj_test(2,200),obj_test(3,300))list from dual ) list_1_objects cross join table(list_1_objects.list) ) list_1_normalized full outer join ( --#2b: List 2 normalized. select id, val from ( --#1b: List 2 objects. select obj_test_list(obj_test(1,300),obj_test(4,500))list from dual ) list_2_objects cross join table(list_2_objects.list) ) list_2_normalized on list_1_normalized.id = list_2_normalized.id );
source share