Hello Folks,
I have this procedure which actually has a MERGE command inside the procedure and basically all it does is it inserts all the data from the temp table when there is no match on the Bill_ID.
Here my requirement is on a daily basis the Bill_ID can be assigned to a different Event_ID. If for example the Bill_ID has changed its event tommorrow the procedure should update the row with the new Event_ID. But in my procedure its not updating because the Bill_ID hasnt changed and its the same(coz am using MERGE insert when not matched). How do i acheive this on a day to day basis. What is the building block of code to do this. Am kinda new to programming and am trying to learn.
CREATE OR REPLACE PROCEDURE load_fadm_staging_area_test (
p_data_load_date DATE
) IS
v_start_date DATE;
v_end_date DATE;
BEGIN
SELECT NVL (p_data_load_date, SYSDATE) - 7,
NVL (p_data_load_date, SYSDATE) - 1
INTO v_start_date,
v_end_date
FROM DUAL;
MERGE INTO stg_fadm_hri_stage_bill_test b
USING (SELECT *
FROM stage_bill
WHERE created_date BETWEEN v_start_date AND v_end_date) a
ON (b.bill_id = a.bill_id,)
WHEN NOT MATCHED THEN
INSERT (batch_id,
beginning_service_date,
bill_id,
bill_method,
bill_number,
bill_received_date,
bill_status,
bill_type,
change_oltp_by,
change_oltp_date,
client_datafeed_code,
client_id,
created_date,
date_of_incident,
date_paid,
deleted_oltp_by,
deleted_oltp_date,
duplicate_bill,
ending_service_date,
event_case_id,
event_id,
from_oltp_by,
oltp_bill_status,
review_status,
row_effective_date,
row_end_date
)
VALUES (a.batch_id,
a.beginning_service_date,
a.bill_id,
a.bill_method,
a.bill_number,
a.bill_received_date,
a.bill_status,
a.bill_type,
a.change_oltp_by,
a.change_oltp_date,
a.client_datafeed_code,
a.client_id,
a.created_date,
a.date_of_incident,
a.date_paid,
a.deleted_oltp_by,
a.deleted_oltp_date,
a.duplicate_bill,
a.ending_service_date,
a.event_case_id,
a.event_id,
a.from_oltp_by,
a.oltp_bill_status,
a.review_status,
v_start_date,
v_end_date
);
END load_fadm_staging_area_test;
Edited by: user11961230 on Jan 26, 2011 9:36 AM