如何从一个表更新一个列并将其从另一个表复制到另一个列?

时间:2015-02-26 21:47:31

标签: sql oracle jobs procedures replicate

我需要每次从表(TYPE)将一列(CUTOMER)从一个表(UNDEF000)复制到另一列(ORDERS)当有人更新要在(TYPE)上自动复制的列(UNDEF000)时,表CUSTOMERORDERS按列(PRE_ORDERCODE)链接。

首先,我尝试从UNDEF000填充TYPE

UPDATE ORDERS 
JOIN CUSTOMER
SET ORDERS.UNDEF000=CUSTOMER.TYPE
WHERE ORDERS.PRE_ORDERCODE= CUSTOMER.PRE_ORDERCODE; 

不起作用:(

UPDATE ORDERS
SET ORDERS.UNDEF000= CUSTOMER.TYPE
FROM CUSTOMER CUSTOMER
INNER JOIN ORDERS ORDERS
ON CUSTOMER.PRE_ORDERCODE= ORDERS.PRE_ORDERCODE

你能帮我解决这两个问题吗?

1 个答案:

答案 0 :(得分:0)

我认为您的更新应该是:

UPDATE ORDERS O SET O.UNDEF000= (
SELECT CUSTOMER.TYPE FROM CUSTOMER 
WHERE CUSTOMER.PRE_ORDERCODE = O.PRE_ORDERCODE); 

触发码:

create or replace trigger after_update_customer after update on
customer for each row
declare

begin
update orders set UNDEF000 = :new.type 
where pre_ordercode = :new.pre_ordercode;
end;