Oracle 实验报告
目录
一、需求分析:.........................................................................................2
二、数据库设计:.....................................................................................2
1、系统功能模块图:...........................................................................2
2、概念结构设计:.............................................................................2
3、逻辑结构设计:.............................................................................3
4、物理结构设计:.............................................................................3
三、编码(详细写出编程步骤):............................................................ 4
步骤分析:...........................................................................................4
程序包代码:.......................................................................................5
四、测试的步骤和内容.............................................................................7
五、课程设计总结.....................................................................................8
一、需求分析:
该考试系统总共分为三大模块
1. 考生个人信息管理子系统
考生、管理员登录;考生、管理员查看个人信息;考生修改个人基本信息;管理
员编辑考生信息(包括添加、修改、删除考生信息);管理员搜索考生信息功能。
2. 基于文件读取的考试子系统
学生登录;答题;交卷;可以保存答案;自己交卷;时间到自动交卷。
3. 监考子系统
监考老师登录;监控考场状态;发卷功能;开始考试;结束考试;搜索考生在线
状态;设置考生状态。
二、数据库设计:
1、系统功能模块图:
网上在线考试系统
考试个人信息管理
考试子系统
监考子系统
2、概念结构设计:
考试状态
1
n
管理员
管理
1
n
n
1
监考老师
n
1
监考
考生
考试
1
试卷
n
组成
n
1
n
选择题
填空题
操作题
3、逻辑结构设计:
Student(sno,sname,sex,age,address,classes,state,examroom,stu_descript
ion,examid,password)
Teacher_admin(tid,tname,tpwd,tidentity,ttel,texamid,tdescribe)
Examstate(estate)
Examfile(fid,fname,fdescription)
Sinsel(sinid,sinname,optiona,optionb,optionc,optiond,coranswer,fid)
Completion(cid,cname,canswer,fid)
Operation(oid,oname,oanswer,fid)
Score(sno,stusinanswer,stucanswer,stuoanswer,sinscore,cscore,oscore,s
umscore,fid)
4、物理结构设计:
学生表 student
老师、管理员表 teacher_admin
考试状态表 examstate
考试文件表 examfile
单选题表 sinsel
填空题表 completion
操作题表 operation
成绩表 score
三、编码(详细写出编程步骤):
步骤分析:
写了一个程序包 teacher_package,内部通过函数、游标、存储过程来完成一些
功能。其返回结果均是变量,通过调用均可获得一个变量来进行前台需求操作。
监考老师和管理员登录函数:
in
teacher_admin.tid%type)
teacher_admin.tpwd%type)
teacher_login(var_identity in teacher_admin.tidentity%type,var_id in
teacher_admin.tid%type,var_pwd
return
number;
输入身份、账号、密码,返回一个数字 0 或 1,分别表示失败和成功登陆。
监考老师查看个人监考的考场号函数:
sel_examid(var_id
in
teacher_admin.texamid%type;
输入监考老师的账号,返回一个考场号变量。
监控考场考生登录各状态数目存储过程:
seestate_stu(onlinenum out int,unonlinenum out int,finishednum out int);
通过对 student 表遍历,输出在线、未在线、考试结束学生数目变量。
监控考场输出未登录考生姓名存储过程:
not_login( t_cur out tcur);
通过对 student 表进行遍历,输出未登录考生姓名结果集变量,内部用的是游标。
改变考试状态存储过程:
update_examstate(v_state in examstate.estate%type);
通过输入一个值 0 或 1 对考试状态 examstate 表进行更新修改。
return
程序包代码:
in
in
in
in
return
sel_examid(var_id
teacher_admin.tidentity%type,var_id
teacher_admin.tpwd%type)
--包头
create or replace package teacher_package
is
type tcur is ref cursor; --定义返回的结果集
--监考老师和管理员登录
function teacher_login(
var_identity
teacher_admin.tid%type,var_pwd
number;
--监考老师查看个人监考的考场号
function
teacher_admin.texamid%type;
--监控考场考生登录各状态数目
procedure
int,finishednum out int);
--监控考场输出未登录考生姓名
procedure not_login( t_cur out tcur);
--改变考试状态
procedure update_examstate(v_state in examstate.estate%type);
end teacher_package;
---------------------------------------------------------------------
--包体
create or replace package body teacher_package is
--监考老师和管理员登录
function teacher_login(
teacher_admin.tid%type)
seestate_stu(onlinenum
return
out
int,unonlinenum
out
var_identity
teacher_admin.tid%type,var_pwd
number is
in
teacher_admin.tidentity%type,var_id
teacher_admin.tpwd%type)
in
in
return
v_pwd teacher_admin.tpwd%type;
v_login number;
begin
select tpwd into v_pwd from teacher_admin where tid=var_id and
tidentity=var_identity;
if v_pwd=var_pwd then
v_login:=1;
else
v_login:=0;
end if;
return v_login;
exception when no_data_found then
raise_application_error(-20002,'该用户不存在');
end;
--监考老师查看个人监考的考场号
function
sel_examid(var_id
teacher_admin.texamid%type is
examid teacher_admin.texamid%type;
begin
in
teacher_admin.tid%type)
return
select texamid into examid from teacher_admin where tid=var_id;
return examid;
end;
--监控考场状态考生登录状态数目
procedure
int,finishednum out int)
seestate_stu(onlinenum
is
out
int,unonlinenum
out
begin
select count(*) into onlinenum from student where state='online';
select count(*) into unonlinenum from student where state='notonline';
select count(*) into finishednum from student where state='finished';
end;
--监控考场状态输出未登录考生姓名
procedure not_login( t_cur out tcur)
is
begin
open t_cur
游标记录结果集
end;
--改变考试状态
procedure update_examstate(v_state in examstate.estate%type)
for select sname from student where state='notonline';--
is
begin
update examstate set estate=v_state;
dbms_output.put_line('考试状态已改为:'||v_state);
end;
end teacher_package;
四、测试的步骤和内容
set serveroutput on;
--监考老师和管理员登录
exec dbms_output.put_line(teacher_package.teacher_login('领导
','002','mark'));
--监考老师查看个人监考的考场号
exec dbms_output.put_line('监考考场为:第
'||teacher_package.sel_examid('001')||'考场');
--监控考场考生登录各状态数目
declare
a int;b int;c int;
begin
teacher_package.seestate_stu(a,b,c);
dbms_output.put_line('未登录:'||a||'人,在线:'||b||'人,结束考试:
'||c||'人');
end;
--监控考场输出未登录考生姓名
var c_cur refcursor;
exec teacher_package.not_login(:c_cur);
print c_cur;
--改变考试状态
exec teacher_package.update_examstate('1');
五、学习体会
通过这次网上在线考试课程设计,对 oracle 这个 DBMS 有了多一些的了解,
也 对 PL/SQL 编 程 有 了 实 践 性 的 应 用 , 如 。 此 次 课 程 设 计 编 码 用 的 工 具 是
SQLDeveloper,编码为后台编码,没有前台界面。其需求分析的各个模块的功能
均用后台程序包的存储过程、函数、游标,还有触发器等实现,当编写前台时就
可以直接调用,无须大量编码,非常方便简单。注意其关键是所编写的 PL/SQL
要有其返回变量,用于在前台编程是接收变量进行功能需要处理,否则编写的
PL/SQL 无法调用,只是后台显示而已,无法被前台利用,无用的代码。还有在
实际应用时,前台通过大量调用后台程序,一些前台能实现的也调用后台程序,
会增加服务器负担,建议能前端实现的留在前端程序实现。通过课程设计的讨论
思考,对此系统的构建,运行过程已熟悉了解,可以将前台实现。