Number of rows affected by an UPDATE in PL/SQL

后端 未结 6 603
暖寄归人
暖寄归人 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:49

    For those who want the results from a plain command, the solution could be:

    begin
      DBMS_OUTPUT.PUT_LINE(TO_Char(SQL%ROWCOUNT)||' rows affected.');
    end;
    

    The basic problem is that SQL%ROWCOUNT is a PL/SQL variable (or function), and cannot be directly accessed from an SQL command. By using a noname PL/SQL block, this can be achieved.

    ... If anyone has a solution to use it in a SELECT Command, I would be interested.

提交回复
热议问题