通过 ROW_COUNT 来判断.
TRUNCATE TABLE output_debug IMMEDIATE@
BEGIN
DECLARE tempCount INT;
INSERT INTO test_main(id, value) VALUES (3, 'THREE');
GET DIAGNOSTICS tempCount = ROW_COUNT;
INSERT INTO output_debug VALUES('插入行:' || TO_CHAR(tempCount));
INSERT INTO test_main(id, value)
SELECT 4, 'FOUR' FROM SYSIBM.SYSDUMMY1 UNION ALL
SELECT 5, 'FIVE' FROM SYSIBM.SYSDUMMY1 ;
GET DIAGNOSTICS tempCount = ROW_COUNT;
INSERT INTO output_debug VALUES('插入行:' || TO_CHAR(tempCount));
update test_main set value = 'FIVE' WHERE id = 5;
GET DIAGNOSTICS tempCount = ROW_COUNT;
INSERT INTO output_debug VALUES('更新行:' || TO_CHAR(tempCount));
END@
db2 => select * from test_main@
ID VALUE
----------- ----------
1 ONE
2 TWO
3 THREE
5 FIVE
4 FOUR
5 条记录已选择。
db2 => select * from output_debug@
DATA
--------------------------------------------------
插入行:1
插入行:2
更新行:1
3 条记录已选择。