数据库实验

        中原工学院 计科161蒋东旗 指导老师杜献峰

       下面的题目在oracle下跑通的,哪位大佬如有改进请积极留言。 其中一部分实验题目,想要全部的可以加我微信jdq8576

  • 创建函数。以课程名作为输入参数,将计科系的该课程成绩低于60分的都提高到60分,更新的人数作为作为函数的返回值
     
CREATE OR REPLACE FUNCTION turing24.Update_SC(name IN turing24.course.cname%type) RETURN NUMBER
IS
     cnt NUMBER;
BEGIN
      UPdate turing24.sc
      SET grade=60
      WHERE grade<60  AND
                   sno IN(select sno from turing24.student where sdept='计科系') AND
                   cno=(select cno from turing24.course where cname=name);
      IF SQL%ROWCOUNT<>0 THEN
            cnt:=SQL%ROWCOUNT;
            RETURN cnt;
      ELSE
            RETURN 0;
      END IF;
END Update_SC;
  • 创建函数,向student表中添加一条学生信息,如果添加成功则返回1,否则返回0
Create or replace function t1 (
sno     student.sno%type
,sname  student.sname%type
,ssex    student.ssex%type
,sage    student.sage%type
,sdept   student.sdept%type
 )
return number
Is
Begin
Insert into student
Values(sno,sname,ssex,sage,sdept);
if sql%rowcount<>0 then return 1;
else
return 0;
end if;
End t1;

  • 利用存储过程,向student表添加一条学生信息
Create or replace procedure insertdata (
sno     student.sno%type
,sname  student.sname%type
,ssex    student.ssex%type
,sage    student.sage%type
,sdept   student.sdept%type
 )
Is
Begin
Insert into student
Values(sno,sname,ssex,sage,sdept);
End insertdata;

猜你喜欢

转载自blog.csdn.net/jdq8576/article/details/80736556