From d78b96587829957eb46f5046ed6a640b8d58e9ff Mon Sep 17 00:00:00 2001 From: HenryChan98 Date: Tue, 31 Jul 2018 14:35:08 +0800 Subject: [PATCH] Update SQL exercises --- other/sql 经典练习题.sql | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/other/sql 经典练习题.sql b/other/sql 经典练习题.sql index 72965fa2..a4b4f964 100644 --- a/other/sql 经典练习题.sql +++ b/other/sql 经典练习题.sql @@ -430,3 +430,54 @@ where SCORE.SNO = STUDENT.SNO and SSEX = '男' and CNO = ( +-- 46、使用游标方式来同时查询每位同学的名字,他所选课程及成绩。 + +declare + cursor student_cursor is + select S.SNO,S.SNAME,C.CNAME,SC.DEGREE as DEGREE + from STUDENT S, COURSE C, SCORE SC + where S.SNO=SC.SNO + and SC.CNO=C.CNO; + + student_row student_cursor%ROWTYPE; + +begin + open student_cursor; + loop + fetch student_cursor INTO student_row; + exit when student_cursor%NOTFOUND; + dbms_output.put_line( student_row.SNO || '' || + +student_row.SNAME|| '' || student_row.CNAME || '' || + +student_row.DEGREE); + end loop; + close student_cursor; +END; +/ + + +-- 47、 声明触发器指令,每当有同学转换班级时执行触发器显示当前和之前所在班级。 + +CREATE OR REPLACE TRIGGER display_class_changes +AFTER DELETE OR INSERT OR UPDATE ON student +FOR EACH ROW +WHEN (NEW.sno > 0) + +BEGIN + + dbms_output.put_line('Old class: ' || :OLD.class); + dbms_output.put_line('New class: ' || :NEW.class); +END; +/ + + +Update student +set class=95031 +where sno=109; + + +-- 48、 删除已设置的触发器指令 + +DROP TRIGGER display_class_changes; +