标签:int values mat 更新 java str acl 对比 bsp
PRODUCTID PRODUCTNAME PRODUCTPRICE QUANTITY CATEGORY ---------- -------------------- ------------ ---------- ---------- DESPERATION -------------------------------------------------------------------------------- ORIGIN ---------- 2 head first java 52 2019 book tecnology UA 1 computer 5000 50 electrical hp_zhan66pro shanghai PRODUCTID PRODUCTNAME PRODUCTPRICE QUANTITY CATEGORY ---------- -------------------- ------------ ---------- ---------- DESPERATION -------------------------------------------------------------------------------- ORIGIN ---------- 3 oracle 80 3000 book it UA 4 dubbo 80 5000 book it PRODUCTID PRODUCTNAME PRODUCTPRICE QUANTITY CATEGORY ---------- -------------------- ------------ ---------- ---------- DESPERATION -------------------------------------------------------------------------------- ORIGIN ---------- UA SQL> select * from productinfo1; PRODUCTID PRODUCTNAME PRODUCTPRICE QUANTITY CATEGORY ---------- -------------------- ------------ ---------- ---------- DESPERATION -------------------------------------------------------------------------------- ORIGIN ---------- 1 iphone 2000 3000 electrical iphone_x shanghai 3 oracle 80 1836 book it UA PRODUCTID PRODUCTNAME PRODUCTPRICE QUANTITY CATEGORY ---------- -------------------- ------------ ---------- ---------- DESPERATION -------------------------------------------------------------------------------- ORIGIN ----------
目的:完成productinfo1表的数据添加和更新(对比productinfo),相同id的quantity更新成productinfo表的,没有的productinfo表中id的数据,全部记录添加到productinfo1表中;
实现语句:
SQL> merge into productinfo1 using productinfo on (productinfo1.productid=productinfo.productid) when matched then update
2 set productinfo1.quantity=productinfo.quantity when not matched then insert
3 values (productinfo.productid,productinfo.productname,productinfo.productprice,productinfo.quantity,productinfo.category,productinfo.desperation,productinfo.origin);
4 行已合并。
实现后的productinfo1表:
1.matched是update,not matched是insert
2.目标表using来源表
3.values后面对应的是来源表的字段,对应字段的数据添加到目标表
标签:int values mat 更新 java str acl 对比 bsp
原文地址:https://www.cnblogs.com/hyp-1901/p/10331299.html