星期二, 5月 06, 2008

在ORACLE/PLSQL裡使用游標FOR迴圈(cursor FOR loop)

藉由從abc_stu資料表內抓取該學號的生日,來更新stu資料表裡每個學號的生日。

DECLARE
CURSOR cur IS
SELECT stuid FROM stu;
BEGIN
FOR rec IN cur
LOOP
UPDATE stu
SET (birth_yr,birth_mm,birth_dd)=
(SELECT birth_yr,birth_mm,birth_dd FROM abc_stu WHERE stuid=rec.stuid)
WHERE stuid=rec.stuid;
END LOOP;
END;

沒有留言: