我有一个表有我想要替换率的列有op_date(04/01/2015)和op_date的比率(04/01/2014)

时间:2016-05-13 09:09:53

标签: sql

将op_date(04/01/2015)的费率替换为具有op_date的费率(04/01/2014) 表记录

enter image description here

1 个答案:

答案 0 :(得分:0)

如果我理解你的问题,答案是:在单个查询中不可能这样做,你需要一个pl / sql脚本。

 declare
  tmp1 number;
  tmp2 number;
 begin
  select rate into tmp1 from yourtable where op_date = to_date (040115,'ddmmrr') and code='cs002';
  select rate into tmp2 from yourtable where op_date = to_date (040114,'ddmmrr') and code='cs002';
  update tablename set rate=tmp1 where op_date = to_date (040114,'ddmmrr') and code='cs002';
  update tablename set rate=tmp2 where op_date = to_date (040115,'ddmmrr') and code='cs002';
  commit;
 end;
 /

请注意,如果费率值对日期和代码

不唯一,则此脚本会出错