Pages

Friday, January 31, 2014

(Sample Procedure) Fetch values from base table using cursor and insertion to custom table

CREATE OR REPLACE PROCEDURE APPS.MON_STK_STAT
(
    p_from in date
)

IS

CURSOR dep_cost IS
SELECT cost_cmpntcls_id,
       source_ind,
       trans_date,
       cost_amt,
       trans_qty,
       cmpntcost_id,
       cost_type_id,
       inventory_item_id,
       organization_id,
       period_id
FROM apps.cm_acst_led cal
WHERE
cal.period_id = (SELECT period_id FROM apps.gmf_period_statuses where to_char(START_DATE, 'MON-YYYY') = to_char(p_from, 'MON-YYYY'));

    begin

        for d in dep_cost
            loop
                insert into APPS.MON_STK_DEP_CST values (d.cost_cmpntcls_id,
                                                                   d.source_ind,
                                                                   d.trans_date,
                                                                   d.cost_amt,
                                                                   d.trans_qty,
                                                                   d.cmpntcost_id,
                                                                   d.cost_type_id,
                                                                   d.inventory_item_id,
                                                                   d.organization_id,
                                                                   d.period_id);
                commit;                                                                
            end loop;
    end;


/

No comments:

Post a Comment