Oracle:如何闪回特定列?

时间:2014-11-12 07:46:24

标签: oracle flashback

如何为表格中的所有行闪回特定列?

例如,给定此表:

select * from t as of scn 1201789714628;
a b 
- - 
x 1 
y 2 
z 3 
select * from t;
a b 
- - 
x 4 
y 5 
z 6 

我可以按如下方式闪回特定行中的列:

update t set b = (select b from t as of scn 1201789714628 where a='x') where a='x';
select * from t;
a b 
- - 
x 1 
y 5 
z 6 

但我无法弄清楚将b设置为所有行的前一个值的语法。

update t t1 set b = (select b from t as of scn 1201789714628) t2 where t1.a = t2.a;
Error at Command Line:11 Column:60
SQL Error: ORA-00933: SQL command not properly ended

1 个答案:

答案 0 :(得分:3)

你可以试试这个:

update t t1 
  set b = (select b from (select a, b from t as of scn 1201789714628) t2
           where t1.a = t2.a);

P.S。如果您现在不打算更新快照,我建议您将快照复制到临时表中(它很快就会消失)。