Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

remove large number of rows

Question posted by: Henry J. (Guest) on July 22nd, 2008 10:45 PM


I'm DB2 newbie. I need to remove large number of rows from a table.
I don't want to fill up the transaction log space. I have the below
SQL that I feed to the db2 command to repeatly remove a fixed set of
rows until there is no more to remove. However db2 complains about
bad syntax. Can anybody advise how I get it right?

Thanks!



DECLARE rows_deleted INT default 1000;
WHILE rows_deleted 0 DO
delete from rcdb.risk_values rv
where rv.PRODUCT_ID_I in
(select pr.PRODUCT_ID_I from
rcdb.risk_values_status rvs, rcdb.PRODUCTS pr
where rvs.UND_SYM_C = pr.UND_SYM_C
fetch first 1000 rows only);
commit;
get diagnostics rows_deleted = row_count;
END WHILE;
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
jefftyzzer's Avatar
jefftyzzer
Guest
n/a Posts
July 22nd, 2008
11:35 PM
#2

Re: remove large number of rows
On Jul 22, 3:39 pm, "Henry J." <tank209...@yahoo.comwrote:
Quote:
Originally Posted by
I'm DB2 newbie. I need to remove large number of rows from a table.
I don't want to fill up the transaction log space. I have the below
SQL that I feed to the db2 command to repeatly remove a fixed set of
rows until there is no more to remove. However db2 complains about
bad syntax. Can anybody advise how I get it right?
>
Thanks!
>
DECLARE rows_deleted INT default 1000;
WHILE rows_deleted 0 DO
delete from rcdb.risk_values rv
where rv.PRODUCT_ID_I in
(select pr.PRODUCT_ID_I from
rcdb.risk_values_status rvs, rcdb.PRODUCTS pr
where rvs.UND_SYM_C = pr.UND_SYM_C
fetch first 1000 rows only);
commit;
get diagnostics rows_deleted = row_count;
END WHILE;


You'll have to do it in either a stored procedure or a BEGIN
ATOMIC...END block.

--Jeff

Serge Rielau's Avatar
Serge Rielau
Guest
n/a Posts
July 23rd, 2008
12:15 PM
#3

Re: remove large number of rows
jefftyzzer wrote:
Quote:
Originally Posted by
On Jul 22, 3:39 pm, "Henry J." <tank209...@yahoo.comwrote:
Quote:
Originally Posted by
>I'm DB2 newbie. I need to remove large number of rows from a table.
>I don't want to fill up the transaction log space. I have the below
>SQL that I feed to the db2 command to repeatly remove a fixed set of
>rows until there is no more to remove. However db2 complains about
>bad syntax. Can anybody advise how I get it right?
>>
>Thanks!
>>
> DECLARE rows_deleted INT default 1000;
> WHILE rows_deleted 0 DO
> delete from rcdb.risk_values rv
> where rv.PRODUCT_ID_I in
> (select pr.PRODUCT_ID_I from
>rcdb.risk_values_status rvs, rcdb.PRODUCTS pr
> where rvs.UND_SYM_C = pr.UND_SYM_C
> fetch first 1000 rows only);
> commit;
> get diagnostics rows_deleted = row_count;
> END WHILE;

>
You'll have to do it in either a stored procedure or a BEGIN
ATOMIC...END block.

Because of the COMMIT it can't be in a dynamic compound (BEGIN ATOMIC)
Anyway: Which version/platform of DB2 and what is the exact syntax error?


--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

 
Not the answer you were looking for? Post your question . . .
182,081 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors