Number of rows affected by an UPDATE in PL/SQL

后端 未结 6 606
暖寄归人
暖寄归人 2020-11-28 22:05

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

6条回答
  •  时光说笑
    2020-11-28 22:55

    You use the sql%rowcount variable.

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

    For example:

    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; 
    

提交回复
热议问题