Skip to content
Advertisement

How can I retrieve an updated script in the oracle database?

How can I retrieve an updated script in the oracle database? An incorrect script was run in the oracle database. I want to get this script back. how can I do that? The script is as follows.

--52 record
 update cons.paymentplan_detail         det set det.payment_date = to_char(ADD_MONTHS(to_Date (det.payment_date, 'YYYYMMDD'),3),'YYYYMMDD')
where det.oid in (select det.oid
  from cons.instalment_instalment_loan ins,
       cons.paymentplan_detail         det,
       cons.paymentplan_def            def,
       (select ins.loans_reference_no,min(det.payment_date) as payment_date
            from cons.instalment_instalment_loan ins,
                cons.paymentplan_detail         det,
                cons.paymentplan_def            def
            where ins.loan_state in ('OPEN', 'BLOCKED')
               and ins.status = '1'
               and def.status = '1'
               and det.status = '1'
               and ins.payment_plan_oid = det.payment_plan_oid
               and det.plan_detail_status  in ('NO','LT')
               and ins.OID='251pfek38q43fg00'
               and def.oid = det.payment_plan_oid
               and def.payment_plan_status = 'GR'
               and def.credit_oid = ins.oid
             group by ins.loans_reference_no) t
 where ins.loan_state in ('OPEN', 'BLOCKED')
   and ins.status = '1'
   and def.status = '1'
   and det.status = '1'
   and ins.payment_plan_oid = det.payment_plan_oid
   and det.plan_detail_status  in ('NO')
   and ins.OID='251pfek38q43fg00'
   and def.oid = det.payment_plan_oid
   and def.payment_plan_status = 'GR'
   and def.credit_oid = ins.oid
   and t.loans_reference_no = ins.loans_reference_no
 group by det.oid);

Advertisement

Answer

If you haven’t COMMITted the data then use ROLLBACK.

Otherwise, your solution could be as simple as running the same query but subtracting 3 months:

update cons.paymentplan_detail det
set det.payment_date = to_char(
                         ADD_MONTHS(
                           to_Date (det.payment_date, 'YYYYMMDD'),
                           -3             -- Changed from +3 to -3
                         ),
                         'YYYYMMDD'
                       )
where ...

If that won’t work and you have COMMITted the data and the database has flashback activated then you can use a flashback query to find the old data from before the UPDATE.

If all that fails, then you can look and see if the database has a recent backup you can restore from.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement