473,395 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

my db2 routine deleting records with commit count ,any advice ?

drop procedure sp_DelTable_CommitCount@
CREATE PROCEDURE sp_DelTable_CommitCount(IN as_TableName VARCHAR(128) ,

IN as_Condition VARCHAR(1024) ,

IN abi_CommitCount BIGINT)

LANGUAGE SQL
BEGIN
DECLARE sm_End SMALLINT DEFAULT 0;
DECLARE retcode INTEGER DEFAULT 0;
DECLARE SQLCODE INTEGER DEFAULT 0;

DECLARE vc_DelStmt VARCHAR(1024);
DECLARE vc_IntactStmt VARCHAR(4096);
DECLARE vc_CreatViewStmt VARCHAR(4096);
DECLARE vc_tmpviewname VARCHAR(128);
DECLARE vc_DropViewStmt VARCHAR(256);
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION, SQLWARNING
BEGIN
EXECUTE IMMEDIATE vc_DropViewStmt ;
RESIGNAL; --给调用者发出原错误信息

END;

DECLARE CONTINUE HANDLER FOR NOT FOUND
SET sm_End = 1;

SET vc_IntactStmt = '( del_tmp_ID ) as select row_number()over()
from '||as_TableName||' where '||as_Condition;
SET vc_tmpviewname = 'tmp_view'||Replace(Replace(Rtrim(char(current
timestamp)),'-',''),'.','');
SET vc_DropViewStmt = 'DROP VIEW '||vc_tmpviewname;
SET vc_CreatViewStmt = ' create view '||vc_tmpviewname||vc_IntactStmt
;

EXECUTE IMMEDIATE vc_CreatViewStmt ;
Commit_Loop:
Loop

SET vc_DelStmt = 'DELETE FROM '||vc_tmpviewname||'
where del_tmp_ID BETWEEN 1 AND '||RTRIM(CHAR(abi_CommitCount));
INSERT INTO TMP4 VALUES (vc_DelStmt);
EXECUTE IMMEDIATE vc_DelStmt;
COMMIT;
IF (sm_End=1) THEN
LEAVE Commit_Loop;
End If ;

End Loop Commit_Loop;

EXECUTE IMMEDIATE vc_DropViewStmt ;

return 0;

END@

Feb 24 '06 #1
2 2448
he******@hotmail.com wrote:
drop procedure sp_DelTable_CommitCount@
CREATE PROCEDURE sp_DelTable_CommitCount(IN as_TableName VARCHAR(128) ,

IN as_Condition VARCHAR(1024) ,

IN abi_CommitCount BIGINT)

LANGUAGE SQL
BEGIN
DECLARE sm_End SMALLINT DEFAULT 0;
DECLARE retcode INTEGER DEFAULT 0;
DECLARE SQLCODE INTEGER DEFAULT 0;

DECLARE vc_DelStmt VARCHAR(1024);
DECLARE vc_IntactStmt VARCHAR(4096);
DECLARE vc_CreatViewStmt VARCHAR(4096);
DECLARE vc_tmpviewname VARCHAR(128);
DECLARE vc_DropViewStmt VARCHAR(256);
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION, SQLWARNING
BEGIN
EXECUTE IMMEDIATE vc_DropViewStmt ;
RESIGNAL; --给调用者发出原错误信息

END;

DECLARE CONTINUE HANDLER FOR NOT FOUND
SET sm_End = 1;

SET vc_IntactStmt = '( del_tmp_ID ) as select row_number()over()
from '||as_TableName||' where '||as_Condition;
SET vc_tmpviewname = 'tmp_view'||Replace(Replace(Rtrim(char(current
timestamp)),'-',''),'.','');
SET vc_DropViewStmt = 'DROP VIEW '||vc_tmpviewname;
SET vc_CreatViewStmt = ' create view '||vc_tmpviewname||vc_IntactStmt
;

EXECUTE IMMEDIATE vc_CreatViewStmt ;
Commit_Loop:
Loop

SET vc_DelStmt = 'DELETE FROM '||vc_tmpviewname||'
where del_tmp_ID BETWEEN 1 AND '||RTRIM(CHAR(abi_CommitCount));
INSERT INTO TMP4 VALUES (vc_DelStmt);
EXECUTE IMMEDIATE vc_DelStmt;
COMMIT;
IF (sm_End=1) THEN
LEAVE Commit_Loop;
End If ;

End Loop Commit_Loop;

EXECUTE IMMEDIATE vc_DropViewStmt ;

return 0;

END@

Which version of DB2 are you on?
Starting in DB2 V8.1.4 you can do thsi a lot simpler (and without the view):
DELETE FROM (SELECT 1 FROM <name> WHERE <condition> FETCH FIRST <n> ROWS
ONLY)
Prepare this one ONCE then EXECUTE in the loop.
If you are prior to V8.1.4 at least move the PREPARE out of the loop.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Feb 24 '06 #2
thx for your help
i do a stupid thing before .. ha

Mar 2 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: rishi | last post by:
Looking for tips on how to improve performance on deleting records. In our database we do dataloads daily that require us to purge millions of records a day so any improvement in speed would be...
8
by: nephish | last post by:
Hey there, sorry , second question in as many days. i am trying to do some stuff with MySQLdb and the thing is, i can select records and such, but when i try to delete them, they dont really go...
3
by: vb | last post by:
I need to delete records from several large tables - 1 million plus rows. Some of these tables have nested foreign key relationships. When I perform the delete statements, it can take forever as...
4
by: BJ | last post by:
Can anyone tell me how to include a count of group records in a group footer. I know (I think I know!) that I have to include an unbound text box in the footer, but what expressions do I use to...
5
by: Mojtaba Faridzad | last post by:
Hi, with SetDataBinding( ) a DataGrid shows a DataView. user can select some rows in the grid by holding cotrol key. when user clicks on Delete button, I should delete all selected rows. I am...
3
by: Chris Thunell | last post by:
I am trying to delete all the records in a table, but I keep getting a system.data.dbconcurrency exception. Is there an easy was to delete all the records in a sql table? Here is my code... i...
10
by: minapatel | last post by:
Hi, I am trying to purge cases using an sql cursor:- cursor all_cases is cursor all_cases is select c.id00_warehouse, c.id00_case_nbr, c.id00_status_flag, c.id00_dlm from phpick00...
24
by: Frank Swarbrick | last post by:
We have a batch process that inserts large numbers (100,000 - 1,000,000) of records into a database each day. (DL/I database.) We're considering converting it to a DB2 table. Currently we have...
0
by: KrazyKoder | last post by:
Hello, I have MS Access form that basically allows the user to configure an update statement to a single table via the gui. A requirement is to show the count of records that will be updated...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.