Friday, 13 January 2012

SELECT AND UPDATE THE SAME QUERT

DECLARE
   CURSOR c1
   IS
      SELECT hou.NAME operating_unit,
             DECODE (hou.NAME,
                     'APIL - HO - 10', 'BILT POWER LTD. HO',
                     'APIL - SHREE GOPAL UNIT - 30', 'BILT POWER LTD,SGU',
                     'APIL - SEWA UNIT - 40', 'BILT POWER LTD,SEW',
                     'APIL - BWN - 50', 'BILT POWER LTD,BWN',
                     'APIL - BWN - 51', 'BILT POWER LTD,BWN',
                     'APIL - BPU UNIT - 20', 'BILT POWER LTD,BPU',
                     'APIL - BPU UNIT - 21', 'BILT POWER LTD,BPU'
                    ) r11i_ou,
             aca.vendor_id, (SELECT segment1
                               FROM apps.po_vendors
                              WHERE vendor_id = aca.vendor_id) vendor_code,
             aca.check_id,
             DECODE (lkup.displayed_field,
                     'Batch', 'Manual',
                     lkup.displayed_field
                    ) payment_type,
             aca.vendor_name vendor_name,
             aca.vendor_site_code vendor_site_code,
             TRUNC (aca.check_date) check_date,
             aca.amount ,
             aca.bank_account_name ,
             aca.payment_method_lookup_code payment_method,
             acs.NAME payment_document,
             NVL (TO_NUMBER (SUBSTR (check_number, -9)),
                  check_number
                 ) check_number,
             aca.currency_code
        FROM apps.ap_checks_all aca,
             apps.ap_lookup_codes lkup,
             apps.ap_check_stocks_all acs,
             apps.hr_operating_units hou
       WHERE lkup.lookup_code = aca.payment_type_flag
         AND lkup.lookup_type = 'PAYMENT TYPE'
         AND acs.check_stock_id(+) = aca.check_stock_id
         AND hou.organization_id = aca.org_id
         AND aca.check_date BETWEEN :p_from_date AND :p_to_date;
BEGIN
   UPDATE xx_ap_checks_11i_r12
      SET r12_operating_unit = NULL,
          r12_check_id = NULL,
          r12_vendor_name = NULL,
          r12_vendor_site_code = NULL,
          r12_check_number = NULL,
          r12_check_date = NULL,
          r12_check_amount = NULL,
          r12_bank_acct_name = NULL,
          r12_currency_code = NULL;
   COMMIT;
   FOR i IN c1
   LOOP
      UPDATE xx_ap_checks_11i_r12
         SET r12_operating_unit = i.operating_unit,
             r12_check_id = i.check_id,
             r12_vendor_name = i.vendor_name,
             r12_vendor_site_code = i.vendor_site_code,
             r12_check_number = i.check_number,
             r12_check_date = i.check_date,
             r12_check_amount = i.amount,
             r12_bank_acct_name = i.bank_account_name,
             r12_currency_code = i.currency_code
       WHERE operating_unit = i.r11i_ou
       AND    NVL (TO_NUMBER (SUBSTR (h_document_number, -9)),
                  h_document_number
                 ) = i.check_number;
   END LOOP;
END;







-------  THANK FOR MANOJ SIR -------

No comments:

Post a Comment