PL/SQL 中受 UPDATE 影响的行数

2021-12-06 00:00:00 sql-update oracle plsql

我有一个 PL/SQL 函数(在 Oracle 10g 上运行),我在其中更新了一些行.有没有办法找出受 UPDATE 影响的行数?手动执行查询时,它告诉我有多少行受到影响,我想在 PL/SQL 中获取该数字.

I have a PL/SQL function (running on Oracle 10g) in which I update some rows. Is there a way to find out how many rows were affected by the UPDATE? When executing the query manually it tells me how many rows were affected, I want to get that number in PL/SQL.

推荐答案

您使用 sql%rowcount 变量.

您需要在需要查找受影响行数的语句之后直接调用它.

You need to call it straight after the statement which you need to find the affected row count for.

例如:

set serveroutput ON; 
DECLARE 
    i NUMBER; 
BEGIN 
    UPDATE employees 
    SET    status = 'fired' 
    WHERE  name LIKE '%Bloggs'; 
    i := SQL%rowcount; 
    --note that assignment has to precede COMMIT
    COMMIT; 
    dbms_output.Put_line(i); 
END; 

相关文章