0

我有一个需要更新日期字段的表:EFFECTIVE_DATE 和 EXPIRATION_DATE。我有 4 行,其中 AGREEMENT_NO = 212132647 和 OFFER_INSTANCE_ID=506412800

AGREEMENT_NO PARAM_SEQ_NO PARAM_NAME            PARAM_VALUES   EFFECTIVE_DATE               EXPIRATION_DATE      OFFER_INSTANCE_ID
------------ ------------ --------------------- -------------- -------------------- -------------------- ---------- 
   212132647    152507704 SDG primary CTN value 3095334348     10-JUN-2013:00:00:00 10-JUN-2013:00:00:00 506412800 

   212132647    152509361 SDG primary CTN value 3095334356     10-JUN-2013:00:00:00 10-JUN-2013:00:00:00 506412800 

   212132647    152509421 SDG primary CTN value 3095334350     10-JUN-2013:00:00:00 10-JUN-2013:00:00:00 506412800 

   212132647    152509464 SDG primary CTN value 3095328533     10-JUN-2013:00:00:00 10-JUN-2013:00:00:00 506412800 

我想更新每个有效日期和到期日期,如下所示:

AGREEMENT_NO PARAM_SEQ_NO PARAM_NAME            PARAM_VALUES   EFFECTIVE_DATE               EXPIRATION_DATE      OFFER_INSTANCE_ID
------------ ------------ --------------------- -------------- -------------------- -------------------- ---------- 
   212132647    152507704 SDG primary CTN value 3095334348     10-JUN-2013:00:00:00 10-JUN-2013:00:00:01 506412800 

   212132647    152509361 SDG primary CTN value 3095334356     10-JUN-2013:00:00:01 10-JUN-2013:00:00:02 506412800 

   212132647    152509421 SDG primary CTN value 3095334350     10-JUN-2013:00:00:02 10-JUN-2013:00:00:03 506412800 

   212132647    152509464 SDG primary CTN value 3095328533     10-JUN-2013:00:00:03 10-JUN-2013:00:00:04 506412800 

有什么方法可以直接更新这些值

update table1 set expiration_date = effective_date + 1/24/3600 where <somecondition>
and for next row: effective_date = old_exp_date + 1/24/3600 , expiration_date = effective_date + 1/24/3600

对于所有行。

4

2 回答 2

0

它非常简单。

您刚刚到达目的地。

您可以点击此链接或以下是您想要的更新声明。

update table1 set expiration_date = effective_date + 1/24/3600 where <somecondition>
and for next row: effective_date = old_exp_date + (1/24/3600)+rownum , expiration_date = effective_date + (1/24/3600)+rownum
于 2013-06-11T12:16:54.450 回答
0

通过计算序列中的记录数,这是一种相当暴力的方法:

update table1
    set effective_date = effective_date +
                          (select count(*) - 1
                           from table1 t2
                           where t2.agreement_no = table1.agreement_no and
                                 t2.expiration_date = table1.expiration_date and
                                 t2.effective_date = table1.effective_date and
                                 t2.param_seq_no <= table1.param_seq_no
                          ) / (24*60*60)
       expiration_date = expiration_date +
                          (select count(*)
                           from table1 t2
                           where t2.agreement_no = table1.agreement_no and
                                 t2.expiration_date = table1.expiration_date and
                                 t2.effective_date = table1.effective_date and
                                 t2.param_seq_no <= table1.param_seq_no
                          ) / (24*60*60)
于 2013-06-11T12:14:21.793 回答