I need to write a PL/SQL code to delete all records except the first 3 for a particular field value in a table.
Does anyone know a fast way of doing it??
Here's just a really high-level example of a PL/SQL statement. It may not be exactly what you're looking for, but I hope it helps in some way.
SELECT FIELD_A AND THE REST OF THE FIELDS
keep_record_counter number(1) := 0;
delete_counter number(5) := 0;
FOR update_rec IN update_cur
If keep_record_counter = 3
delete the rest of the records
IF field_a = whatever
keep the record
add one to the keep_record_counter
delete the record
add one to the delete_counter
If the delete_counter := 5000
do a commit
[Edited by smoothyc on 02-28-2001 at 09:54 AM]
Click Here to Expand Forum to Full Width