Monday, May 9, 2011

Show Plan for a query

explain plan set statement_id = '123456' for
delete from dup1 d1
where rowid >
( select min(rowid) from dup1 d2 where d1.num = d2.num );


SELECT LPAD(' ',2*(level-1)) || operation || ' ' || options || ' '
||object_name||' '||
DECODE(id,0,'Cost = '|| position) AS "Query Plan"
FROM plan_table
START WITH id = 0
AND statement_id='123456'
CONNECT BY PRIOR ID = PARENT_ID
AND statement_id = '123456';

Delete Duplicate Rows from a table

delete from dup1 d1
where rowid >
( select min(rowid) from dup1 d2 where d1.num = d2.num )

OR

delete from dup1 d1
where rowid  <
( select max(rowid) from dup1 d2 where d1.num = d2.num )