简体   繁体   中英

How can I update and replicate one column from one table to another column from another table?

I need to replicate one column ( TYPE ) from one table ( CUTOMER ) to another column ( UNDEF000 ) from table ( ORDERS ), by this way everytime when someone update column( TYPE ) to be automaticaly replicated on ( UNDEF000 ), Table CUSTOMER and ORDERS are linked by column ( PRE_ORDERCODE ).

First I try to fill UNDEF000 from TYPE :

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

not function :(

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

Can you please help me with this two problems?

I think your update should be like:

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

Trigger code:

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM