by 공기 [Oracle 기초] [2020.01.02 19:43:24]
~아래와 같은 구분이 오라클에서도 가능한가요?
UPDATE MMTABLE M
SET ID = X.ID
,CO_NM = X.CO_NM
,CUST_NM = X.CUST_NM
FROM
(
SELECT B.ID
B.CUST_NM
,B.CO_NM
FROM BBTABLE B
,CCTABLE C
WHERE B.ID = C.ID
) X
WHERE M.ID = X.ID
http://gurubee.net/article/79308
-- 1.1. SubQuery - IN UPDATE mmtable m SET (co_nm, cust_nm) = (SELECT b.co_nm , b.cust_nm FROM bbtable b , cctable c WHERE b.id = c.id AND b.id = m.id ) WHERE id IN (SELECT b.id FROM bbtable b , cctable c WHERE b.id = c.id ) ; -- 1.2. SubQuery - Exists UPDATE mmtable m SET (co_nm, cust_nm) = (SELECT b.co_nm , b.cust_nm FROM bbtable b , cctable c WHERE b.id = c.id AND b.id = m.id ) WHERE EXISTS (SELECT 1 FROM bbtable b , cctable c WHERE b.id = c.id AND b.id = m.id ) ; -- 2. Updatable Join View (b.id 및 c.id 가 PK 일때만 가능) UPDATE (SELECT m.co_nm , m.cust_nm , b.co_nm co_nm_new , b.cust_nm cust_nm_new FROM bbtable b , cctable c , mmtable m WHERE b.id = c.id AND b.id = m.id ) SET co_nm = co_nm_new , cust_nm = cust_nm_new ; -- 3. Merge MERGE INTO mmtable m USING (SELECT b.id , b.co_nm , b.cust_nm FROM bbtable b , cctable c WHERE b.id = c.id ) x ON (m.id = x.id) WHEN MATCHED THEN UPDATE SET co_nm = x.co_nm , cust_nm = x.cust_nm ; -- http://gurubee.net/article/79308