I am attempting to update the GPID
field of table DIM_TRADING_ACCOUNTS
based on the GPID
field of MASTER_CUSTOMER
where the MCUST_CODE
in MASTER_CUSTOMER
is equal to the TRADING_CODE
of DIM_TRADING_ACCOUNTS
and no matter what I try, I get what basically amounts to an syntax error each time.
I have been taking guidance from this question. The four attempts I have made so far are below along with errors. Can someone please help me get the proper syntax for oracle SQL that works?
Note: I used upper on mcust_code
because the trading_code
field is all upper-case
Attempt 1 (error is: SQL command not properly ended)
UPDATE dim_trading_accounts dta
SET dta.gpid = mc.gpid
FROM master_customer mc
WHERE UPPER(mc.mcust_code) = dta.trading_code;
Attempt 2 (error is: missing "SET" keyword)
UPDATE
dim_trading_accounts dta, master_customer mc
SET
dta.gpid = mc.gpid
WHERE
upper(mc.mcust_code) = dta.trading_code;
Attempt 3 (this one returns error: single-row subquery returns more than one row)
UPDATE dim_trading_accounts dta
SET dta.gpid = (SELECT mc.gpid
FROM master_customer mc
WHERE dta.trading_code = upper(mc.mcust_code))
WHERE EXISTS (SELECT 1
FROM master_customer mc
WHERE dta.trading_code = upper(mc.mcust_code));
Attempt 4 (error is: missing "ON" keyword)
MERGE INTO dim_trading_accounts
USING master_customer
ON dim_trading_accounts.trading_code = upper(master_customer.mcust_code)
WHEN MATCHED THEN
UPDATE
SET dim_trading_accounts.gpid = master_customer.gpid;