Home » SQL & PL/SQL » SQL & PL/SQL » Merge collections ?
Merge collections ? [message #625902] Wed, 15 October 2014 19:18 Go to next message
lijjumathew
Messages: 2
Registered: October 2014
Junior Member
I need to merge two collections. I know two tables can be merged , but not sure of collections.
What is the best way to merge collections ?
Say below is the sample code

------------
CREATE OR REPLACE TYPE obj_test AS OBJECT(
id number(9),
val number (9)
)
/

CREATE OR REPLACE TYPE obj_test_list AS TABLE OF obj_test
/

I have two lists/collections

list1 obj_test_list ;
list2 obj_test_list ;
list3 obj_test_list ;


list1 list2
id val id val
1 100 1 300
2 200 4 500
3 300

I want to match list1 and list2 based on id and add val else insert.
I want it in list3 as follows.

list3
id val
1 400
2 200
3 300
4 500

Can someone give a sample code for this?

Thanks
Matt
Re: Merge collections ? [message #625903 is a reply to message #625902] Wed, 15 October 2014 19:30 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Welcome to this forum.

Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/ and read http://www.orafaq.com/forum/t/174502/

>What is the best way to merge collections ?
avoid using collections since they only add complication & difficulty to manipulate them.
Re: Merge collections ? [message #625904 is a reply to message #625903] Wed, 15 October 2014 22:50 Go to previous message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
Might be helpful, similar question in SO https://stackoverflow.com/questions/26394356/merge-collections-in-oracle
Previous Topic: DBMS_SCHEDULER and perl script
Next Topic: Replace every even number occurance of comma with # in a String
Goto Forum:
  


Current Time: Fri Mar 29 03:44:47 CDT 2024