所以让我在程序中有3个合并语句:
CREATE PROCEDURE SP_Employee(OUT num_rows BIGINT)
BEGIN
MERGE INTO t1
USING t2
...;
MERGE INTO a1
USING b2
...;
MERGE INTO c1
USING d2
...;
END;
如何在程序中获得受影响的行数?我知道ACTIVE_COUNT,但我可以使用它吗? num_rows = ACTIVE_COUNT
是否有效,或者需要多次将其添加到变量并最初设置为0?
答案 0 :(得分:1)
您可以在每次合并后插入下面的部分。
Merge INTO t1
USING t2
.....;
SET lv_activity_count = activity_count;
SET lv_message = ' Number of rows merged in table1 is '|| lv_activity_count ;
..
请初始化并声明变量。
答案 1 :(得分:1)
您需要将变量初始化为零,然后在每次执行DML语句后添加计数(使用ACTIVITY_COUNT或GET DIAGNOSTICS ROW_COUNT):
CREATE PROCEDURE SP_Employee(OUT num_rows BIGINT)
BEGIN
DECLARE ac BIGINT DEFAULT 0;
MERGE INTO t1
USING t2
...;
SET ac = ac + ACTIVITY_COUNT;
MERGE INTO a1
USING b2
...;
SET ac = ac + ACTIVITY_COUNT;
MERGE INTO c1
USING d2
...;
SET ac = ac + ACTIVITY_COUNT;
SET num_rows = ac;
END;