我在BI数据库中有一个带有空日期(CREATED_ON_DT
)的表A.我需要使用数据库链接mtl_system_items_b@afldev
使用AFLDEV DB中的正确日期更新这些空值。公钥是AFLDEV中的inventory_item_id
和BI DB中的integration_id
。我已经构建了以下查询,但它不起作用:
UPDATE w_product_d
SET w_product_d.CREATED_ON_DT = (SELECT min(creation_date)
FROM mtl_system_items_b@afldev B
where to_char(B.inventory_item_id)=w_product_d.integration_id
and B.organization_id = '102'
AND w_product_d.CREATED_ON_DT IS NULL
and w_product_d.integration_id in (SELECT T.integration_id
FROM (SELECT * FROM w_product_d ORDER BY w_product_d.integration_id )T
WHERE T.CREATED_ON_DT IS NULL)
);
如果我运行此查询,它会将所有日期更新为空,但我需要相反的情况发生,即用正确的日期替换null。
请帮我解决这个问题!我在SQL Developer for Oracle DB上这样做。
答案 0 :(得分:0)
我认为您已经完全更新了您要更新的行和您用来更新列值的行。
如果您考虑一下,您想要更新w_product_d表中created_on_dt为null的行,这意味着您的update语句将具有以下基本结构:
update w_product_d wpd
set ...
where wpd.created_on_dt is null;
完成后,您可以轻松插入要更新的列以及您使用以下内容进行更新:
update w_product_d wpd
set wpd.created_on_dt = (select min(creation_date)
from mtl_system_items_b@afldev b
where to_char(b.inventory_item_id) = wpd.integration_id)
where wpd.created_on_dt is null;