我正在使用DB2 9.7 for Z / oS。我有一个包含超过100万行的表,我想删除大约900万行。我尝试过以下存储过程,但没有成功。
CREATE PROCEDURE DELETE_DATA
(IN V_TABLE_NAME VARCHAR(24),
IN V_COMMIT_COUNT INTEGER,
IN V_WHERE_CONDITION VARCHAR(1024))
DYNAMIC RESULT SETS 01
COMMIT ON RETURN NO
LANGUAGE SQL
NOT DETERMINISTIC
L3 : BEGIN
-- DECLARE STATEMENTS
DECLARE SQLCODE INTEGER;
DECLARE V_DELETE_QUERY VARCHAR(1024);
DECLARE V_DELETE_STATEMENT STATEMENT;
SET V_DELETE_QUERY = 'DELETE FROM ' || V_TABLE_NAME ||
' WHERE COLUMN IN (SELECT COLUMN FROM '
|| V_TABLE_NAME || 'WHERE COLUMN_ID ='
|| V_WHERE_CONDITION || ' FETCH FIRST '
|| RTRIM(CHAR(V_COMMIT_COUNT)) || ' ROWS ONLY) ';
PREPARE V_DELETE_STATEMENT FROM V_DELETE_QUERY;
DEL_LOOP:
LOOP
EXECUTE V_DELETE_STATEMENT;
IF SQLCODE = 100 THEN
LEAVE DEL_LOOP;
END IF;
COMMIT;
END LOOP;
COMMIT;
END L3
建议我对上述存储过程进行任何更改。
答案 0 :(得分:2)
将要保留的数据提取到适合输入sql loader实用程序的文件中。生成新数据,也生成适合输入到sql loader的文件。截断目标表。使用两个输入文件运行Sql加载程序。干净,简单,可重复,并且不会加载日志文件。