Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: Very long query
Zach,
To avoid this problem, the procedure described below commits after every N number of rows specified by the user so that rollback segments are not taxed.
--This procedure deletes rows from the table specified in tname for
the condition in where_clause. It commits after every n records
specified by the parameter commit_size .
-- eg : execute delete_table('emp','where job=''clerk''',2000);
CREATE OR REPLACE PROCEDURE delete_table
(tname in varchar2, where_clause in varchar2 default null, commit_size in numberdefault 1000) is
sel_id INTEGER; del_id INTEGER; exec_sel INTEGER; exec_del INTEGER;
DBMS_SQL.PARSE(sel_id,cur_stmt,dbms_sql.v7); DBMS_SQL.DEFINE_COLUMN_ROWID(sel_id,1,del_rowid); exec_sel := DBMS_SQL.EXECUTE(sel_id);--Prepare cursor to delete records
' where rowid = :del_rowid',dbms_sql.v7);
LOOP
IF DBMS_SQL.FETCH_ROWS(sel_id) >0 THEN
--Get the rowid to be deleted DBMS_SQL.COLUMN_VALUE(sel_id,1,del_rowid); DBMS_SQL.BIND_VARIABLE(del_id,'del_rowid',del_rowid); --Execute the delete for the rowid got exec_del := DBMS_SQL.EXECUTE(del_id); -- Commit for every n records where n is specified in commit_size if mod(dbms_sql.last_row_count,commit_size) = 0 then COMMIT; end if;
Thanassis Mylonas
On Thu, 10 Dec 1998 07:55:37 +0100, Rolf Hauck <Rolf.Hauck_at_datenrevision.de> wrote:
>Did you check for locks on your table? >Why don't you commit inside the loop? > >Rolf > >Zachary Agatstein schrieb: >> >... >> Why if I can successfully delete 1000 records, I cannot consecutively delete >> all of them in 1000-record chunks? >> >> Thanks >> >> Zach AgatsteinReceived on Thu Dec 10 1998 - 06:10:45 CST
![]() |
![]() |