ORACLE关于merge into用法!MERGE INTO MSA2008BS.ATYW_ZS_GCZL AUSING (SELECT * fROM LOADTMP.MSA2008BS_ATYW_ZS_GCZL WHERE ETL_F IN ('I','D','A')) BON (A.ATZSCZLOID=B.ATZSCZLOID)WHEN MATCHED AND B.SHIPFID ='' THEN UPDATE SETA.SHIPFID =B.SHIPFID ,A.GCZ

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/27 18:40:12
ORACLE关于merge into用法!MERGE INTO MSA2008BS.ATYW_ZS_GCZL AUSING (SELECT * fROM LOADTMP.MSA2008BS_ATYW_ZS_GCZL WHERE ETL_F IN ('I','D','A')) BON (A.ATZSCZLOID=B.ATZSCZLOID)WHEN MATCHED AND B.SHIPFID ='' THEN UPDATE SETA.SHIPFID =B.SHIPFID ,A.GCZ
xUOPWΞfOK.V23^NIm毡f(Yа)*'3MLlm|9;Zc^cwq$UFH2z+{ń#x3x|p睞n0󜋳 pnpyVpMP8W lr(cX%xt:abA܌`wp,0l4pv9Y0@P^8997Q yXۮ߾h~w jh.7D֥aRsc{7ښnc{*L' $Ԑ9paT36eE5=wq9l2̗2dG5ѾM#-UvʺT9"ETd~̬TA:B x̖"L$j%J\*Câ:ΕA~-i:ë!1#d8IuB>d@[D,sML`‘O-24<*&@N/*c) "$$M@aAP[D^JHlyR)lAwN~aHj_:^i -uQ.,IR6D|&‘یN& JiS^Vi淁"[o/ɺ5Hyr WPip: ږ"vj Sv#)*{zs֫ðF%Ui+bP(UuWiB;-yEmj[CRD-kq3FpZ4W~,

ORACLE关于merge into用法!MERGE INTO MSA2008BS.ATYW_ZS_GCZL AUSING (SELECT * fROM LOADTMP.MSA2008BS_ATYW_ZS_GCZL WHERE ETL_F IN ('I','D','A')) BON (A.ATZSCZLOID=B.ATZSCZLOID)WHEN MATCHED AND B.SHIPFID ='' THEN UPDATE SETA.SHIPFID =B.SHIPFID ,A.GCZ
ORACLE关于merge into用法!
MERGE INTO MSA2008BS.ATYW_ZS_GCZL A
USING (SELECT * fROM LOADTMP.MSA2008BS_ATYW_ZS_GCZL WHERE ETL_F IN ('I','D','A')) B
ON (A.ATZSCZLOID=B.ATZSCZLOID)
WHEN MATCHED AND B.SHIPFID ='' THEN UPDATE SET
A.SHIPFID =B.SHIPFID ,
A.GCZLDJZHM=B.GCZLDJZHM ,
A.CBDJH =B.CBDJH
WHEN NOT MATCHED THEN
INSERT(A.ATZSCZLOID,A.SHIPFID,A.GCZLDJZHM,A.CBDJH,A.CBCZR)
VALUES(B.ATZSCZLOID,B.SHIPFID,B.GCZLDJZHM,B.CBDJH,B.CBCZR)
;
中因为在WHEN MATCHED后加入了AND条件即:AND B.SHIPFID =''
之后报错,是不是oracle不支持WHEN MATCHED后跟条件呢?

ORACLE关于merge into用法!MERGE INTO MSA2008BS.ATYW_ZS_GCZL AUSING (SELECT * fROM LOADTMP.MSA2008BS_ATYW_ZS_GCZL WHERE ETL_F IN ('I','D','A')) BON (A.ATZSCZLOID=B.ATZSCZLOID)WHEN MATCHED AND B.SHIPFID ='' THEN UPDATE SETA.SHIPFID =B.SHIPFID ,A.GCZ
在when matched then 和 when not matched then 后面只能加insert() values 或者 update set .,. ,不能附加条件,而且then 后面的语句不能使用其他语句. 另外注意到,B的域只在using里面的查询有用吧 ,如果你要使用 也得是 在Using () M 用m吧

WHERE只能跟在数据库对象之后,比如表和视图

qiyechao
说的很对,when matched then 和 when not matched then 后面只能加insert() values 或者 update set ,B的域只在using里面的查询有用,AND B.SHIPFID ='' 写在using里面,即
MERGE INTO MSA2008BS.ATYW_ZS_GCZL A
USING (SELE...

全部展开

qiyechao
说的很对,when matched then 和 when not matched then 后面只能加insert() values 或者 update set ,B的域只在using里面的查询有用,AND B.SHIPFID ='' 写在using里面,即
MERGE INTO MSA2008BS.ATYW_ZS_GCZL A
USING (SELECT * fROM LOADTMP.MSA2008BS_ATYW_ZS_GCZL WHERE ETL_F IN ('I','D','A') AND B.SHIPFID ='' ) B
ON (A.ATZSCZLOID=B.ATZSCZLOID)
WHEN MATCHED THEN UPDATE SET
A.SHIPFID =B.SHIPFID ,
A.GCZLDJZHM=B.GCZLDJZHM ,
A.CBDJH =B.CBDJH
WHEN NOT MATCHED THEN
INSERT(A.ATZSCZLOID,A.SHIPFID,A.GCZLDJZHM,A.CBDJH,A.CBCZR)
VALUES(B.ATZSCZLOID,B.SHIPFID,B.GCZLDJZHM,B.CBDJH,B.CBCZR)

收起