问题描述
如果记录的特定列被更新,我们需要提取表的数据。我们可以使用 “上次更新日期” 列找到表的更新行。有没有办法找到该行的哪一列得到更新?
专家解答
做到这一点的最佳方法是启用某种形式的审计,以捕获表的旧状态。
如果您还没有这样做,并且更新是 “最近”,那么您可以使用闪回查询来比较表的新旧状态:
所以你可以看到每一列的值。
您可以走多远取决于您的undo_retention以及数据库上发生的其他更改数量。如果要保证一段时间的历史记录,可以启用闪回数据存档https://www.oracle.com/ocom/groups/public/@otn/documents/webcontent/4421812.pdf
如果您还没有这样做,并且更新是 “最近”,那么您可以使用闪回查询来比较表的新旧状态:
create table t ( c1 primary key, c2, c3, c4 ) as
select level, 'large text', sysdate, systimestamp
from dual
connect by level <= 100;
exec dbms_lock.sleep ( 5 );
select current_scn from v$database;
CURRENT_SCN
28444485
update t
set c2 = 'new text'
where c1 = 1;
update t
set c3 = sysdate + 1
where c1 = 2;
commit;
select t.*, versions_operation, versions_startscn scn_from, versions_endscn scn_to
from t
versions between scn 28444485 and maxvalue
where c1 = 1;
C1 C2 C3 C4 VERSIONS_OPERATION SCN_FROM SCN_TO
1 new text 21-APR-2020 08:23:59 21-APR-2020 08.23.59 +00 U 28444494
1 large text 21-APR-2020 08:23:59 21-APR-2020 08.23.59 +00 28444494
select t.*, versions_operation, versions_startscn scn_from, versions_endscn scn_to
from t
versions between scn 28444485 and maxvalue
where c1 = 2;
C1 C2 C3 C4 VERSIONS_OPERATION SCN_FROM SCN_TO
2 large text 22-APR-2020 08:24:07 21-APR-2020 08.23.59 +00 U 28444494
2 large text 21-APR-2020 08:23:59 21-APR-2020 08.23.59 +00 28444494 所以你可以看到每一列的值。
您可以走多远取决于您的undo_retention以及数据库上发生的其他更改数量。如果要保证一段时间的历史记录,可以启用闪回数据存档https://www.oracle.com/ocom/groups/public/@otn/documents/webcontent/4421812.pdf
文章转载自ASKTOM,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




