When I check the 'Display optimised sql', I get:-
MERGE INTO "TMP_xxx" s
USING
(SELECT *
FROM ...
WHERE ..
) n
ON ((s.NATURAL_KEY = n.NATURAL_KEY))
WHEN MATCHED THEN
UPDATE SET ..
WHEN NOT MATCHED THEN
INSERT /*+ APPEND */ ...
VALUES (...)
But when I check the actual sqls which are pushed down to Oracle for execution, I get different sqls:-
SELECT ... FROM ...
and
DECLARE LOCAL_VAR INT;
BEGIN
SELECT COUNT(*) INTO LOCAL_VAR
FROM "TMP_xxx"
WHERE "NATURAL_KEY" = :AL_BeforeVariable0 ;
IF (LOCAL_VAR = 0) THEN
INSERT INTO "TMP_xxx"
VALUES ( ...)
ELSE
UPDATE "TMP_xxx"
SET "yyy" = :AL_AfterVariable0,
...
WHERE "NATURAL_KEY" = :AL_BeforeVariable0
;
END IF;
END
; .
The "Merge SQL", which had been displacyed, did not get pushed down to database. Instead, a 'SELECT' and IF .. INSERT .. ELSE UPDATE sqls were pushed to the database.
Something even worse happened. The insert/updates were pushed to the database one row at a time.
Please advise how do get DS to push the "Merge SQL" to the database for execution?
Thanks in advance
Peng Lim