Oracle2014课程设计题with answer 联系客服

发布时间 : 星期四 文章Oracle2014课程设计题with answer更新完毕开始阅读8974c83db84ae45c3b358cb0

图为只读。

create view v_count_1(借书证号,总借阅本数) as

select r_id,count(*) from borrow group by r_id with read only

6.创建一个借阅统计视图,名为V_Count_2,包含借阅总本数大于两本的读者号和总借阅本数。

create view v_count_2(读者号,总借阅本数) as

select r_id,count(*) from borrow group by r_id having count(*)>=2

7.修改视图V_Pub,要求增加图书的单价信息,并且该视图进行的更新操作只涉及“人民邮电出版社”。

create or replace view v_pub as

select b_id,b_name,price,publish.* from book,publish where publish.p_id=book.p_id and pubname='人民邮电出版社' with check option 8.删除视图V_Pub。 drop view v_pub

9.创建序列S_BookUser,要求初值为1,序列增量为2,没有最大值限制。 create sequence s_bookuser start with 1 increment by 2 10.修改序列S_BookUser的最大值为1000。 alter sequence s_bookuser maxvalue 1000 11.新建表Test(UserID NUMBER,UserName VARCHAR2(10)),向表中插入两条数据,其中UserID字段由序列S_BookUser提供,并查看表test是否插入成功。 create table test(UserID NUMBER,UserName VARCHAR2(10)) insert into test values(s_bookuser.nextval,'tom') 12.删除序列S_BookUser。 drop sequence s_bookuser

【任务8】常量、变量和系统函数

1.编写程序实现将Reader表中借书证号为“2004186001”的读者的姓名赋值给变量r_name,并输出该变量的值。 declare

r_name varchar2(20); begin

select R_name into r_name from reader where r_id='2004186001';

dbms_output.put_line('20041086001读者名为:'||r_name); end;

2.输出当前系统日期月份和年份。 begin

dbms_output.put_line(extract(month from sysdate)); dbms_output.put_line(extract(year from sysdate)); end;

3.使用字符函数统计字符串“ SQL Server 2008 ”的长度。 begin

dbms_output.put_line(length(' SQL Server 2008 ')); end;

4.使用函数删除字符串“ SQL Server 2008 ”左右两端的窗格并输出。 begin

dbms_output.put_line(trim(' SQL Server 2008 ')); end;

【任务9】流程控制语句

1.编写PL/SQL语句块,求2~500之间的素数和。 declare

s number:=0;

flag boolean:=true; begin

for i in 2..500 loop for j in 2..i-1 loop if mod(i,j)=0 then flag:=false; end if; end loop; if flag then s:=s+i; end if;

flag:=true; end loop;

dbms_output.put_line('sum is'||s); end;

2.编写PL/SQL语句块,使用IF语句求出3个数中最大的数。 declare i number; j number; k number;

maxnum number; begin i:=12; j:=9; k:=7;

maxnum:=i;

if maxnum

dbms_output.put_line('max is'||maxnum); end; 或

DECLARE

m number;n number;l number;maxnum number; BEGIN

m:=18;n:=8;l:=14;

if m>n and m>l then maxnum:=m; elsif n>l then maxnum:=n; else maxnum:=l; end if;

dbms_output.put_line('max is '||maxnum); END;

3.编写PL/SQL语句块,要求使用循环结构来计算10!。 declare

s number:=1; begin

for i in 1..10 loop s:=s*i; end loop;

dbms_output.put_line('sum is'||s); end;

4.查询图书中有没有英语书和SQL Server方面的书,如果有则统计其册数。 declare

e_count number:=0; o_count number:=0;

cursor bookcur is select b_name from book; bname_book book.b_name%type; begin

if bookcur%isopen=false then open bookcur; end if;

fetch bookcur into bname_book; while bookcur%found loop

if instr(bname_book,'英语')>0 then e_count:=e_count+1;

elsif instr(bname_book,'SQL SERVER')>0 then o_count:=o_count+1; end if;

fetch bookcur into bname_book; exit when bookcur%notfound; end loop;

close bookcur;

dbms_output.put_line('英语书的数量为:'||e_count);

dbms_output.put_line('SQL SERVER书的数量为:'||o_count); end;

【任务10】存储过程

1.创建存储过程PRO_Borrow,返回还未归还图书的读者借书证号、读者姓名、借阅日期、图书名称和图书作者。

create or replace procedure pro_borrow is

cursor pro_borrow_cur is

select borrow.b_id,r_name,lenddate,b_name,author from borrow,book,reader where borrow.r_id=reader.r_id and borrow.b_id=book.b_id and returndate is null;

bid borrow.b_id%type; zhuozhe varchar2(20); shuming varchar2(20); borrowday date; duzhe varchar2(20); begin

open pro_borrow_cur;

fetch pro_borrow_cur into bid,duzhe,borrowday,shuming,zhuozhe; while pro_borrow_cur%found loop

dbms_output.put_line(bid||','||duzhe||','||borrowday||','||shuming||','||zhuozhe); fetch pro_borrow_cur into bid,duzhe,borrowday,shuming,zhuozhe; end loop;

close pro_borrow_cur; end;

2.调用存储过程PRO_Borrow,查询所有未还图书的详细信息。 exec pro_borrow begin

pro_borrow; end;

3.创建带参数的存储过程PRO_Borrow_RID,要求该存储过程能够根据输入的借书证号返回该读者的所有借阅信息,包括借阅日期、还书日期、图书名称、图书ISBN号。 create or replace procedure pro_borrow_rid(rid in varchar2) is

cursor pro_borrow_rid_cur(rid varchar2) is select lenddate,returndate,b_name,isbn from

borrow,book where borrow.b_id=book.b_id and borrow.r_id=rid; code varchar2(20); shuming varchar2(20); returnday date; borrowday date; begin

open pro_borrow_rid_cur(rid);

fetch pro_borrow_rid_cur into borrowday,returnday,shuming,code;

dbms_output.put_line(rid||','||borrowday||','||returnday||','||shuming||','||code); close pro_borrow_rid_cur; end;

4.调用存储过程PRO_Borrow_RID,查询借书证号为“2010211110”的读者的借阅信息。 exec pro_borrow_rid(‘2010211110’)

5.修改存储过程PRO_Borrow_RID,要求修改后的存储过程根据输入的借书证号返回该读者的所有借阅信息,包括读者姓名、借阅日期、还书日期、图书名称、图书ISBN号。 create or replace procedure pro_borrow_rid(rid in varchar2) is

cursor pro_borrow_rid_cur(rid varchar2) is

select r_name,lenddate,returndate,b_name,isbn from

reader,borrow,book where reader.r_id=borrow.r_id and borrow.b_id=book.b_id and borrow.r_id=rid;