ORACLE关于merge into用法!
MERGEINTOMSA2008BS.ATYW_ZS_GCZLAUSING(SELECT*fROMLOADTMP.MSA2008BS_ATYW_ZS_GCZLWHEREE...
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后跟条件呢?大神帮忙..... 展开
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后跟条件呢?大神帮忙..... 展开
3个回答
展开全部
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)
说的很对,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)
展开全部
在when matched then 和 when not matched then 后面只能加insert() values 或者 update set ....,.... ,不能附加条件,而且then 后面的语句不能使用其他语句。 另外注意到,B的域只在using里面的查询有用吧 ,如果你要使用 也得是 在Using () M 用m吧
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
WHERE只能跟在数据库对象之后,比如表和视图
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询