oracle10g上的代码
MERGE INTO TCGGYSGHCP CP
USING (SELECT *
FROM (SELECT QD.LIFNR,
QD.MATNR,
MAX(MX.DATAB) DATAB,
MAX(MX.DATBI) DATBI,
QD.LOEKZ,
QD.SESSIONID,
MAX(QD.CREATEDATE) CREATEDATE,
QD.STATUS
FROM T_SAP2SCF_GHCP QD
LEFT JOIN A018 MX
ON MX.SESSIONID = QD.SESSIONID
AND MX.MATNR = QD.MATNR
AND MX.LIFNR = QD.LIFNR
WHERE QD.SESSIONID = P_SESSIONID
GROUP BY QD.LIFNR,
QD.MATNR,
QD.LOEKZ,
QD.SESSIONID,
QD.STATUS)) T
ON (CP.WLBM = T.MATNR AND CP.GYSBM = T.LIFNR)
WHEN MATCHED THEN
UPDATE
SET CP.ISDELETE = T.LOEKZ,
CP.TCCYTZSRQ = T.DATAB,
CP.TCQXTZSRQ = T.DATBI,
CP.GYSMC =
(SELECT XX.GYSMC FROM TCGGYSXX XX WHERE XX.GYSBM = T.LIFNR),
CP.WLMC =
(SELECT WL.WLMC FROM TPRIWLZSJ WL WHERE WL.WLBM = MATNR)
WHEN NOT MATCHED THEN
INSERT
(ZZBM,
ZZXLH,
WLBM,
WLMC,
ISDELETE,
TCCYTZSRQ,
TCQXTZSRQ,
GYSBM,
GYSMC)
VALUES
('5920',
'1003',
MATNR,
(SELECT WL.WLMC FROM TPRIWLZSJ WL WHERE WL.WLBM = MATNR),
LOEKZ,
DATAB,
DATBI,
LIFNR,
(SELECT XX.GYSMC FROM TCGGYSXX XX WHERE XX.GYSBM = T.LIFNR));
这段代码在oracle11g中编译报错
经过跟踪发现 子操作中的子查询去掉就可以,在此可以把子操作中的子查询数据放入到主查询中,子操作直接引用即可。