Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 Oracle PL/SQL: Eliminate duplicate records Jump to:  
Category: >> Oracle PL/SQL >> Eliminate duplicate records Bookmark and Share

<< lastnext >>

Snippet Name: Eliminate duplicate records

Description: Simply runs through the table and eliminates duplicate records. Very fast.

Comment: (none)

Language: PL/SQL
Highlight Mode: PLSQL
Last Modified: February 27th, 2009

CREATE OR REPLACE PROCEDURE dupes AS
 
CURSOR dupes_cur IS
SELECT task_code, ROWID
FROM jwc_task_code_test
ORDER BY task_code;
 
dupes_rec dupes_cur%ROWTYPE;
 
prev_val      VARCHAR2(100);
cur_val      VARCHAR2(100);
 
 
BEGIN
 
OPEN dupes_cur;
prev_val := '';
 
     LOOP
 
          FETCH dupes_cur INTO dupes_rec;
          EXIT WHEN dupes_cur%notfound;
 
 
          IF prev_val = dupes_rec.task_code
          THEN 
               DELETE 
               FROM jwc_task_code_test
               WHERE ROWID = dupes_rec.ROWID;
          ELSE NULL;
          END IF;
 
          prev_val :=  dupes_rec.task_code;
 
     END LOOP;
 
CLOSE dupes_cur;
 
END dupes;


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 302 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?