Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

union all-distinct and remove duplicates from nested table?

alinuxJun 16 2008 — edited Jun 17 2008
Hi all,

I need a select that will bulk collect some data in my nested table.

I have two tables from which I need to select all the accounts only once.(remove duplicates).
Tried to search on the forum...but no luck.

I have a table with one column:

create table a1(account_no number);

and a second table with 3 columns.
create table a2 (account_no number, name number, desc varchar2 (100));

I have a nested table like:

table of a2%rowtype;

Can I select from this two table in one select and put in my nested table just one row per account?

if a I have in a 2a row like :
1 'test' 'test2'
2 aaaa aa
and in a1 a row like:
1
I want to put in my nested table just (1, null,null and 2,aaaa, aa)) or (1,test,test2 and 2,aaaa, aa). it does no matter what row from those two I insert.


Second question:
If I use:
BANNER
----------------------------------------------------------------
Oracle9i Release 9.2.0.5.0 - Production
PL/SQL Release 9.2.0.5.0 - Production
CORE 9.2.0.6.0 Production
TNS for 32-bit Windows: Version 9.2.0.5.0 - Production
NLSRTL Version 9.2.0.5.0 - Production

SQL>


what is the best solution to remove duplicates from a neste table like mine?

I thought that I can build another nested table and loop in my first nt and for each row I check in there was the same account in previous lines.

it will be like:
for i in 1....nt_first.count loop
 for j in 1..i loop
    --check if my line was in previous lines. if it was...do not move it in my second collection

end loop;
it is this best option in oracle 9i?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 15 2008
Added on Jun 16 2008
13 comments
2,511 views