leolo’s Blog



在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;


發表迴響

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 變更 )

Twitter picture

You are commenting using your Twitter account. Log Out / 變更 )

Facebook照片

You are commenting using your Facebook account. Log Out / 變更 )

連結到 %s

Follow

Get every new post delivered to your Inbox.