MERGE INTO BAS_F T
USING (SELECT MON.COMMODITY_ID,
AVG(SEL.FLUCTUATION_RATIO) AVG,
SUM(SEL.FLUCTUATION_RATIO) / COUNT(*)
FROM BAS_O SEL, BAS_O_C MON
WHERE SEL.STATUS = 'N'
AND SEL.O_COMMODITY_ID = MON.O_COMMODITY_ID
AND MON.STATUS = 'N'
GROUP BY MON.COMMODITY_ID) MM
ON (T.COMMODITY_ID = MM.COMMODITY_ID)
WHEN MATCHED THEN
UPDATE SET T.FLUCTUATION_RATIO = MM.AVG;
报错:PCC-F-02102, Encountered the symbol "MERGE" when expecting one of the following:
for, register, at, close, commit, connect, declare, describe,
execute, fetch, open, prepare, rollback, select, whenever,
alter, audit, comment, create, delete, drop, get, grant,
insert, lock, noaudit, rename, revoke, set, update, validate,
arraylen, allocate, cache, call, collection, context,
deallocate, enable, free, lob, object, savepoint, analyze,
explain, truncate,
The symbol "alter," was substituted for "MERGE" to continue.
------解决思路----------------------
结合你的语句可以简化
update BAS_F T
set FLUCTUATION_RATIO =(
SELECT AVG(SEL.FLUCTUATION_RATIO)
FROM BAS_O SEL, BAS_O_C MON
WHERE SEL.STATUS = 'N'
AND SEL.O_COMMODITY_ID = MON.O_COMMODITY_ID
AND MON.STATUS = 'N'
and T.COMMODITY_ID = MM.COMMODITY_ID
)
where exists (SELECT 1
FROM BAS_O SEL, BAS_O_C MON
WHERE SEL.STATUS = 'N'
AND SEL.O_COMMODITY_ID = MON.O_COMMODITY_ID
AND MON.STATUS = 'N'
and T.COMMODITY_ID = MM.COMMODITY_ID)