Number of rows affected by rollback

I need to know the number of rows affected by the rollback. How can i get this? Please, help.

+3
source share
4 answers

Consider a table fred with two columns (id, value) with two rows. The first line (1, "Blue"), the second - (2, "Blue")

I go out the following statements

INSERT INTO fred VALUES (1,'Red'); [inserts 1 row]
UPDATE fred SET value = 'Blue';    [updates 3 rows but the value on 2 doesn't change]
UPDATE fred SET id = 3 WHERE id = 1; [updates 1 row]
ROLLBACK;

Both entries originally presented in the table have been updated. 1 has been updated twice. One row was inserted and then updated. Then all these changes were canceled. The question is which number do you want? The number of updated records or the total number of updates made to the records.

, , - . . , , UPDATE, , , . Ref AskTom

+6

, , . , , (A in ACID). , , .

+5

, oracle, // SQL%ROWCOUNT, ,

+4
declare
  i number:=0;
begin
  INSERT INTO fred VALUES (1,'Red'); [inserts 1 row]
  i := i + sql%rowcount;
  UPDATE fred SET value = 'Blue';    [updates 3 rows but the value on 2 doesn't change]
  i := i + sql%rowcount;  
  UPDATE fred SET id = 3 WHERE id = 1; [updates 1 row]
  i := i + sql%rowcount;
  if <condition> then
      COMMIT;
      dbms_output.PUT_LINE(i || ' rows COMMITED';
      i := 0;
  else
      ROLLBACK;
      dbms_output.PUT_LINE(i || ' rows ROLLBACK';
      i := 0;
  end if;
end;
0
source

Source: https://habr.com/ru/post/1746500/


All Articles