Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Remove duplicates from a field possible?
"Mark Milke" <mark_milke_at_yahoo.com> a écrit dans le message de news: 1141630427.043643.309240_at_u72g2000cwu.googlegroups.com...
| Hi all,
|
| we store in a var field values in the format 123; 345; 567; In some
| records the field contains duplicates, i.e. 123; 345; 123; 567; Is it
| possible to selelct those records somehow, or even better get rid of
| the duplicates?
|
| Mark
|
SQL> select * from t order by id;
ID VALS
---------- ------------------------------ 1 123; 345; 123; 567; 2 abc; cde; abc; efg;
2 rows selected.
SQL> def max_vals=10 SQL> col vals format a30 SQL> with 2 step1 as ( 3 select id, vals, rn 4 from t, (select rownum rn from dual connect by level <= &max_vals)5 ),
7 select distinct 8 id, 9 trim(substr(vals, 10 decode(rn,1,0,instr(vals,';',1,rn-1))+1, 11 instr(vals,';',1,rn) 12 -decode(rn,1,0,instr(vals,';',1,rn-1))-1)) val 13 from step1 14 where instr(vals,';',1,rn) > 0
17 select id, val, 18 row_number () over (partition by id order by val) curr, 19 row_number () over (partition by id order by val)-1 prev 20 from step2
ID VALS
---------- ------------------------------ 1 123;345;567; 2 abc;cde;efg;
2 rows selected.
Regards
Michel Cadot
Received on Mon Mar 06 2006 - 10:56:53 CST