前端之家收集整理的这篇文章主要介绍了
Oracle merge into 记录,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
MERGE INTO table_name(目的表) table_alias USING (table/view/sub_query)//数据来源(可以用子查询)alias(别名) on(连接条件) WHEN MATCHED THEN UPDATE SET(关键字) (修改目的表) 目的表AL.col1=原表AL.col_var1 目的表AL.col2=原表AL.col2_var2 WHEN NOT MATCHEN THEN(关键字) INSERT (目的表AL.COL_LIST) VALUES(原表AL.COL_VARS);(插入原表)
MERGE INTO products p USING newproducts np ON (p.product_id = np.product_id) WHEN MATCHED THEN UPDATE SET p.product_name = np.product_name,p.category = np.category WHERE np.category = 'BOOKS' WHEN NOT MATCHED THEN INSERT VALUES (np.product_id,np.product_name,np.category) WHERE np.category = 'BOOKS'