[英]Oracle database, update data from 1 table to another
我在 oracle 12c 數據庫中有 2 個表,我想從 1 個表更新到下一個表。
表 1(EMBLEMTEMPLATE 等):
et.emblemtemplate_id, et.customer_id, et.code
表 2(產品列表PERCUSTOMER):
plpc.productlistpercustomer_id, plpc.customer_id, plpc.emblemtemplate_id,
我正在嘗試做的事情:
我創建了一個 select:
select plpc.customer_id,
plpc.productlistpercustomer_id,
plpc.emblemtemplate_id,
et.customer_id,
et.emblemtemplate_id,
et.code
from productlistpercustomer plpc
inner join emblemtemplate et
on et.customer_id = plpc.customer_id
where et.code = '999991'
有人可以幫我把它翻譯成 sql 更新腳本嗎?
謝謝!
您可以嘗試使用帶有相關子查詢的更新:
UPDATE
productlistpercustomer plpc
SET
emblemtemplate_id = (SELECT et.emblemtemplate_id
FROM emblemtemplate et
WHERE et.customer_id = plpc.customer_id AND
et.code = '999991')
WHERE
emblemtemplate_id IS NULL;
merge
怎么樣?
MERGE INTO productlistpercustomer p
USING emblemtemplate e
ON (e.customer_id = p.customer_id)
WHEN MATCHED
THEN
UPDATE SET p.emblemtemplate_id = p.emblemtemplate_id
WHERE e.code = 999991
AND p.emblemtemplate_id IS NULL;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.