Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

How to Display Number of Rows Deleted/Inserted etc... in PL/SQL

AAlsofyaniSep 9 2011 — edited Sep 9 2011
In Oracle 10g PL/SQL, I have a delete statement in a stored procedure. It is not in a cursor. I want to see the number of rows I've deleted. I can use the dbms_output.put_line package. I should know this, but I don't have time to perfect the syntax. How would I get the number of rows that get deleted and display it via dbms_output.put_lline?
This post has been answered by 513949 on Sep 9 2011
Jump to Answer

Comments

513949
Answer
For example:
set serveroutput on

begin

   delete  dept;
   
   dbms_output.put_line(sql%rowcount);
   
end;
/  
Miguel
Marked as Answer by AAlsofyani · Sep 27 2020
32685
No time to google either I guess.
http://www.google.co.uk/search?q=number+of+rows+deleted+oracle&rls=com.microsoft:en-gb&ie=UTF-8&oe=UTF-8&startIndex=&startPage=1&rlz=&redir_esc=&ei=Qi5qToGyGYqw8QOGzf3nAg
SQL> create table dt_del_ex(id number);

Table created.

SQL> set serveroutput on
SQL> BEGIN
  2
  3      INSERT INTO dt_del_ex VALUES(1);
  4
  5      DBMS_OUTPUT.put_line(TO_CHAR(SQL%ROWCOUNT)||' rows inserted');
  6
  7      INSERT INTO dt_del_ex select rownum from dual connect by level <=10;
  8
  9      DBMS_OUTPUT.put_line(TO_CHAR(SQL%ROWCOUNT)||' rows inserted');
 10
 11      UPDATE dt_del_ex SET id = id + 3 WHERE id >= 9;
 12
 13      DBMS_OUTPUT.put_line(TO_CHAR(SQL%ROWCOUNT)||' rows updated');
 14
 15      DELETE FROM dt_del_ex WHERE id <= 10;
 16
 17      DBMS_OUTPUT.put_line(TO_CHAR(SQL%ROWCOUNT)||' rows deleted');
 18
 19  END;
 20  /
1 rows inserted
10 rows inserted
2 rows updated
9 rows deleted

PL/SQL procedure successfully completed.
AAlsofyani
I Do Thanks!
1 - 3
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Oct 7 2011
Added on Sep 9 2011
3 comments
68,874 views