The following Merge statement is not Inserting (going to NOT MATCHED) the record.
The query used in the Condition part of the Merge clause sometimes will not return any row.
Is this causing the Insert to not happen?
MERGE INTO apps.test_table ab USING
(SELECT batch_id
FROM apps.test_table
WHERE session_name='session_name'
AND status ='NOT STARTED'
)b ON (ab.batch_id=b.batch_id)
WHEN MATCHED THEN
UPDATE
SET STATUS ='RUNNING',
tag_receive_time = sysdate,
sess_start_time = SYSDATE,
wflw_start_time = sysdate
WHERE batch_id = b.batch_id
WHEN NOT MATCHED THEN
INSERT
(
ab.batch_id,
ab.status,
ab.workflow_name,
ab.session_name,
ab.source_name,
ab.target_table,
ab.created_by,
ab.creation_date,
ab.snapshot_date,
ab.tag_receive_time,
ab.sess_start_time,
ab.wflw_start_time
)
VALUES
(
apps.batch_id_seq.nextval,
'RUNNING',
'$PMWorkflowName',
'$PMSessionName',
'AMPS',
'SPARES_F_ORDER_SHIPMENT_DTL',
'Informatica',
SYSDATE,
SYSDATE,
SYSDATE,
SYSDATE,
SYSDATE
)
;