I have a db table that has > 14M rows.
If I attempt to perform:
delete from table
The connection hangs out.
How can I delete all the rows, in "batchs" ( I guess ) so they are deleted eventually?
I have a db table that has > 14M rows.
If I attempt to perform:
delete from table
The connection hangs out.
How can I delete all the rows, in "batchs" ( I guess ) so they are deleted eventually?
Try out:
truncate table tblname
This has the advantage of not being rollback-able so will not have to log its actions, and also does not fire triggers. That makes it substantially faster than the equivalent delete from tblname
.
Otherwise, you can work out subsets to delete, based on your table data. For example, if there's a field (hopefully indexed) containing last names:
delete from tblname where lastname like 'A%'
Note that this is just an example. You can also use things like
and so on. What you choose depends entirely on the table you're trying to delete.
I prefer the truncate
command myself due to its simplicity.
deletes are logged operation which can be rolled back, hence they can be quite slow. If you can truncate or drop and recreate the table, that's your best bet. Alternatively, you can execute this sql.
BEGIN
loop
delete from table where rownum < 500
exit when SQL%rowcount < 499
end loop;
END