BEGIN FOR l IN (SELECT table1.no AS no, table2.phone AS phone FROM table2, table1 WHERE table1.NO = table2.NO) LOOP UPDATE table1 SET table1.phone = l.phone WHERE table1.no = l.no; END LOOP; COMMIT; END; /
Oracle 강좌탭에서 PL/SQL강좌 참고하세요~
BEGIN FOR l IN (SELECT table1.no AS no, table2.phone AS phone FROM table2, table1 WHERE table1.NO = table2.NO) LOOP UPDATE table1 SET table1.phone = l.phone WHERE table1.no = l.no; END LOOP; COMMIT; END; /
Oracle 강좌탭에서 PL/SQL강좌 참고하세요~
-- PL/SQL -- DECLARE CURSOR cur1 IS SELECT * FROM table2; BEGIN FOR c1 IN cur1 LOOP UPDATE table1 SET phone = c1.phone WHERE no = c1.no ; END LOOP; COMMIT; EXCEPTION WHEN OTHERS THEN ROLLBACK; END; / -- One SQL -- UPDATE table1 t1 SET phone = (SELECT phone FROM table2 t2 WHERE t2.no = t1.no) ;