如何获取受UPDATE语句影响的行数



我正在尝试获取受UPDATE语句影响的行数,但我得到了以下错误:

ORA-06550: line 2, column 9:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
constant exception <an identifier>
<a double-quoted delimited-identifier> table columns long
double ref char time timestamp interval date binary national
character nchar
The symbol "exception" was substituted for ";" to continue.

我正在执行的查询如下:

DECLARE 
var_rows; 
BEGIN 
var_rows:=SQL%ROWCOUNT; 
UPDATE {Product} SET {Product}.[Name] = concat({Product}.[Name], ' - test') WHERE {Product}.[ProductTypeId] = 2; 
SELECT var_rows FROM DUAL; 
END;

正确使用SQL%rowcount。即紧接在update之后

示例

create table tab1 as 
select 1 id, 'a' col from dual union all
select 1, 'b' from dual;

set serveroutput on;
declare
rn int;
begin 
update tab1 
set col = 'z';
rn := SQL%rowcount; 
dbms_output.put_line(rn);
end;
/

2

PL/SQL procedure successfully completed.

最新更新