Thursday, 15 May 2014

oracle - PL SQL find duplicate in collection -



oracle - PL SQL find duplicate in collection -

i have collection below.

id name ----- ------- 1 2 3 b 4 c

i want check whether duplicate values there in collection. possible in pl/sql

you can utilize plsql's built in set operator "set" create set unique values , compare original collection. can utilize set operator "except" them:

declare type tt table of varchar2(10); orig tt; tmp tt; begin orig := tt('a', 'b', 'b', 'b', 'c', 'd', 'a'); tmp := set(orig); if (tmp.count = orig.count) dbms_output.put_line('no duplicates'); else dbms_output.put_line('there duplicates:'); tmp := set(orig multiset except tmp); in 1 .. tmp.count loop dbms_output.put_line(tmp(i)); end loop; end if; end; /

oracle plsql

No comments:

Post a Comment