受回滚影响的行数

发布于 2024-09-02 07:45:54 字数 36 浏览 3 评论 0原文

我需要找出受回滚影响的行数。 我怎样才能得到这个?请帮忙。

I need to find out the number of rows affected by a rollback.
How can I get this ? Please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

涙—继续流 2024-09-09 07:45:54

考虑一个具有两列(id,值)和两行的表 fred。
第一行是 (1,'Blue'),第二行是 (2,'Blue')

我发出以下语句

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;

表中最初的两条记录均已更新。 1更新了两次。插入一行然后更新。然后所有这些更改都被回滚。问题是,你想要什么数字?更新的记录数,或对记录执行的更新总数。

从技术角度来看,最简单的答案是统计 应用的撤消记录数。但你必须在之前和之后进行测量。实际上,它可能会变得非常令人困惑,因为对于涉及并发活动的 UPDATE 语句,语句可能会中途停止、回滚并重新启动。参考 AskTom

Consider a table fred with two columns (id, value) with two rows.
The first row is (1,'Blue') and the second is (2,'Blue')

I issue 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 records originally in the table have been updated. 1 was updated twice. One row was inserted and then updated. Then all those changes were rolled back. The question is, what number do you want ? The number of records updated, or the total number of updates performed to records.

The easiest answer to get, from a technical point of view, is the statistic number of undo records applied. But you'd have to measure this before and after. Actually, it can get very confusing because with an UPDATE statement that hits concurrent activity, a statement may be stopped part way through, rolled back and restarted. Ref AskTom

微暖i 2024-09-09 07:45:54

实际上,受回滚影响的行数。这是因为,从技术上讲,这些行在提交发生之前不会更改(ACID 中的 A)。而且,如果您回滚,则不会发生提交。

Actually, the number of rows affected by a rollback is zero. That's because, technically, those rows aren't changed until a commit occurs (the A in ACID). And, if you're rolling back, the commit doesn't happen.

二货你真萌 2024-09-09 07:45:54

我不知道如何使用 Oracle 执行此操作,但您可以使用 SQL%ROWCOUNT 跟踪创建/更改/删除的行,这样您就知道回滚中会影响什么

I dont know of a way to do this with oracle, but you could potentially keep track of your created/altered/deleted rows using SQL%ROWCOUNT so you know what will be affected in a rollback

难以启齿的温柔 2024-09-09 07:45:54
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;
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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文