...如何返回SQL影响的条数 如oracle中的sql%rowcount。
发布网友
发布时间:2024-09-17 04:53
我来回答
共1个回答
热心网友
时间:2024-11-10 18:22
通过 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 条记录已选择。