CREATE OR REPLACE PROCEDURE P_MERGE_MMCTP(ORDERID VARCHAR2, FLAG VARCHAR2) AS
BEGIN
IF (FLAG = 'S') THEN MERGE INTO ctp A
USING (SELECT 001 FROM a_FILE
WHERE 001 = ORDERID) B
ON (A.001 = B.001)
WHEN MATCHED THEN
UPDATE SET A.001= A.001 + 1
WHEN NOT MATCHED THEN
INSERT (001) VALUES (ORDERID);
ELSIF (FLAG = 'R') THEN
UPDATE TC_MMCTP_FILE
SET 003= 003+ 1
WHERE 001= ORDERID;
COMMIT;
END IF;
END P_MERGE_MMCTP;