Oracle课程设计题withansweranswerwith.docx

上传人:b****5 文档编号:6593941 上传时间:2023-01-08 格式:DOCX 页数:7 大小:20.09KB
下载 相关 举报
Oracle课程设计题withansweranswerwith.docx_第1页
第1页 / 共7页
Oracle课程设计题withansweranswerwith.docx_第2页
第2页 / 共7页
Oracle课程设计题withansweranswerwith.docx_第3页
第3页 / 共7页
Oracle课程设计题withansweranswerwith.docx_第4页
第4页 / 共7页
Oracle课程设计题withansweranswerwith.docx_第5页
第5页 / 共7页
点击查看更多>>
下载资源
资源描述

Oracle课程设计题withansweranswerwith.docx

《Oracle课程设计题withansweranswerwith.docx》由会员分享,可在线阅读,更多相关《Oracle课程设计题withansweranswerwith.docx(7页珍藏版)》请在冰豆网上搜索。

Oracle课程设计题withansweranswerwith.docx

Oracle课程设计题withansweranswerwith

Oracle2014课程设计题with,answeranswerwith

Oracle课程设计报告姓名班级学号指导教师20XX年X月X日《Oracle课程设计》大纲一、课程设计目的和要求1.掌握数据库的设计和管理方法,巩固SQLServer中数据库、表、视图、索引、存储过程、触发器等基本操作。

2.掌握PL/SQL编程语言的应用。

3.巩固数据查询的各种方法。

二、具体要求1.本课程设计使用软件为Oracle11g。

2.本课程设计共20学时,设计结束上交课程设计报告一份。

3.考核方式:

考勤成绩(20%)+报告成绩(80%)。

三、课程设计报告具体格式1.封面2.正文分三部分:

(1)课程设计目的和要求

(2)课程设计内容(3)课程设计总结四、课程设计内容在数据库中创建一个以自己姓名拼音首字母缩写的账户,密码为学号。

在此方案下进行设计任务。

【任务1】创建数据表1.使用OEM工具创建Book(图书表)和BookType(图书类型表)Book表字段名称数据类型长度说明B_IDCHAR9图书编号B_Name*****240图书名称Author*****220作者BT_IDCHAR2图书类别,外键P_IDCHAR4出版社编号PubDateDATE出版日期PriceNUMBER(5,2)价格BookType表字段名称数据类型长度说明BT_IDCHAR2图书类别编号,主键BT_Name*****220图书类别名称BT_Info*****250描述信息2.使用SQL语句创建Reader表(读者表)和ReaderType表(读者类型表)。

Reader表字段名称数据类型长度说明R_IDCHAR10读者借书证编号,主键R_Name*****28读者姓名RT_IDCHAR1读者类型,外键RDept*****212部门RTel*****211联系电话ReaderType表字段名称数据类型长度说明RT_IDCHAR1读者类型编号,主键RT_Name*****210读者类型姓名LimitNumNUMBER限借数量LimitDaysNUMBER限借天数3.使用SQLDeveloper工具创建Borrow表(借阅表)和Publish表(出版社表)。

Borrow表字段名称数据类型长度说明R_IDCHAR10读者借书证编号B_IDCHAR9图书编号LendDateDATE借阅日期ReturnDateDATE还书日期LimitDaysNUMBER限借天数BorrowInfo*****22是否过期Publish表字段名称数据类型长度说明P_IDCHAR4出版社编号PubName*****230出版社名称PubTel*****220联系电话latto/lattocreatetableReader(R_IDchar(10)primarykey,R_Namevarchar2(8),RT_IDnumber

(1),RDeptvarchar2(10),RTelvarchar2(11))tablespaceuserscreatetableReaderType(RT_IDchar

(1)primarykey,RT_Namevarchar2(10),LimitNumnumber,LimitDaysnumber)tablespaceuserscreatetableReader(R_IDchar(10)primarykey,R_Namevarchar2(8),RT_IDchar

(1),RDeptvarchar2(10),RTelvarchar2(11))tablespaceusersaltertablereaderaddconstraintfk_RT_IDforeignkey(RT_ID)referencesReaderType(RT_ID)createtableBorrow(R_IDchar(10),B_IDchar(9),LendDateDate,ReturnDateDate,LimitDaysnumber,BorrowInfovarchar2

(2))tablespaceuserscreatetablePublish(P_IDchar(4),PubNamevarchar2(30),PubTelvarchar2(20))tablespaceusers【任务2】修改数据表1.将Reader表中的联系电话字段的数据类型修改为*****2(20)。

altertablereadermodifyrtelvarchar2(20)2.指定Borrow表的借阅日期LendDate不允许为空。

altertableborrowmodifylenddatedatenotnull3.删除Borrow表中的限借天数LimitDays字段。

altertableborrowdropcolumnlimitdays4.为Book表增加ISBN字段,数据类型为*****2(13)。

altertablebookaddISBNvarchar2(13)【任务3】建立约束1.为Book表添加主键,约束名为PK_Book。

altertablebookaddconstraintPK_Bookprimarykey(B_ID)2.为Borrow表添加主键,主键是(R_ID,B_ID,LendDate),约束名为PK_Borrow。

altertableborrowaddconstraintPK_Borrowprimarykey(R_ID,B_ID,LendDate)3.设置Book表的出版社编号字段P_ID是外键,参照Publish表中的P_ID,约束名为FK_book_pub。

altertablepublishaddconstraintpk_pubprimarykey(P_ID)altertablebookaddconstraintFK_book_pubforeignkey(P_ID)referencesPublish(P_ID)4.为Book表中的价格字段Price添加检查约束,要求价格必须大于0,约束名为CHK_price。

altertablebookaddconstraintchk_pricecheck(price0)5.为Reader表增加性别(Rsex)字段,数据类型为CHAR

(2),并设默认值为“男”。

updatereadersetrdept=“保卫处"wherer_name="张芳"3.使用SQL语言删除Publish表中“北京交大出版社”的记录。

deletefrompublishwherepubname="北京交大出版社"【任务6】简单查询及连接查询1.查询所有图书的基本信息。

select*frombook2.查询所有的图书编号、图书名称和价格。

selectb_id,b_name,pricefrombook3.查询教师一次可以借书数量以及借书天数,输出的结果字段名分别用借书本数和借书期限表示。

selectlimitnumas借书本数,limitdaysas借书期限fromreadertypewherert_name="教师"4.查询姓“张”读者的基本信息。

select*fromreaderwherer_namelike"张%"5.查询Borrow表中未还图书的记录。

select*fromborrowwherereturndateisnull6.查询2014年的借阅记录。

select*fromborrowwhereto_char(lenddate,"yyyy")=20147.统计图书信息表中不同出版社出版的图书数目,把统计结果大于或等于2的结果输出。

selectp_id,count(*)aspubnumfrombookgroupbyp_idhavingcount(*)=2selectp_id,count(p_id)aspubnumfrombookgroupbyp_idhavingcount(p_id)=28.查询Borrow表中所有借书的读者的借书证号、姓名以及所借图书的图书证号。

selectborrow.r_id,r_name,b_idfromborrow,readerwhereborrow.r_id=reader.r_id9.查询Borrow表中所有借书的读者的借书证号、姓名以及所借图书的图书的详细信息。

selectreader.r_id,r_name,book.*fromborrow,reader,bookwhereborrow.r_id=reader.r_idandbook.b_id=borrow.b_id10.查询借阅了书籍的读者和没有借阅的读者,显示他们的读者号、姓名、书名、借阅日期。

selectreader.r_id,r_name,book.b_name,lenddatefrombook,reader,borrowwherereader.r_id=borrow.r_id(+)andbook.b_id(+)=borrow.b_idselectb_name,price,pubnamefrombook,publishwherebook.p_id=publish.p_idandpubnamein("人民邮电出版社","高等教育出版社")11.查询“人民邮电出版社”的图书中单价比“高等教育出版社”最高单价还高的图书名、单价。

selectb_name,pricefrombook,publishwherebook.p_id=publish.p_idandpubname="人民邮电出版社"andpriceall(selectpricefrombook,publishwherebook.p_id=publish.p_idandpubname="高等教育出版社")12.查询从未被借阅过的图书信息。

select*frombookwhereb_idnotin(selectb_idfromborrow)/selectb_namefrombook,borrowwherebook.b_id=borrow.b_idselectp_id,count(*)aspubnumfrombookgroupbyp_id13.查询每一个出版社出版的书籍的数量。

selectpubname,count(*)aspubnumfrombook,publishwherebook.p_id=publish.p_idgroupbypubname14.查询与《SQLSERVER应用技术》同一类型的所有图书的名称、作者、ISBN号。

selectb_name,author,isbnfrombookwherebt_id=(selectbt_idfrombookwhereb_name="SQLSERVER应用技术")15.查询所有单价小于平均单价的图书号、书名、出版社。

16.查询与《SQLSERVER应用技术》同一出版社的所有图书的图书名称、作者、ISBN号。

17.查询姓名为“杨倩”的读者的借阅记录。

selectr_name,borrow.*fromreader,borrowwhereborrow.r_id=reader.r_idandr_name="杨倩"18.查询姓名为“杨倩”的读者的所借图书的详细信息。

selectbook.*fromreader,borrow,bookwhereborrow.r_id=reader.r_idandbook.b_id=borrow.b_idandr_name="杨倩"19.查询借阅了“高等教育出版社”出版的书名中包含有“数据库”3个字的图书,或者借阅了“中国铁道出版社”出版的书名中含有“SQL”3个字的图书的读者姓名、书名。

selectr_name,b_namefrombook,borrow,publish,readerwherereader.r_id=borrow.r_idandbook.b_id=borrow.b_idandbook.p_id=publish.p_idandpubname="高等教育出版社"andb_namelike"%数据库%"unionselectr_name,b_namefrombook,borrow,publish,readerwherereader.r_id=borrow.r_idandbook.b_id=borrow.b_idandbook.p_id=publish.p_idandpubname="中国铁道出版社"andb_namelike"%SQL%"20.查询借阅了“高等教育出版社”出版的书名中包含有“数据库”3个字的图书,并且也借阅了“中国铁道出版社”出版的书名中含有“SQL”3个字的图书的读者姓名。

selectr_namefrombook,borrow,publish,readerwherereader.r_id=borrow.r_idandbook.b_id=borrow.b_idandbook.p_id=publish.p_idandpubname="高等教育出版社"andb_namelike"%数据库%"intersectselectr_namefrombook,borrow,publish,readerwherereader.r_id=borrow.r_idandbook.b_id=borrow.b_idandbook.p_id=publish.p_idandpubname="中国铁道出版社"andb_namelike"%SQL%"21.查询借阅了“高等教育出版社”出版的书名中包含有“数据库”3个字的图书,但是没有借阅了“中国铁道出版社”出版的书名中含有“SQL”3个字的图书的读者姓名。

selectr_namefrombook,borrow,publish,readerwherereader.r_id=borrow.r_idandbook.b_id=borrow.b_idandbook.p_id=publish.p_idandpubname="高等教育出版社"andb_namelike"%数据库%"minusselectr_namefrombook,borrow,publish,readerwherereader.r_id=borrow.r_idandbook.b_id=borrow.b_idandbook.p_id=publish.p_idandpubname="中国铁道出版社"andb_namelike"%SQL%"【任务7】索引、视图、序列及同义词1.为Book图书表的书名列创建惟一索引idx_Bname。

createuniqueindexidx_bnameonbook(b_name)2.将索引“idx_Bname”重命名为index_Bname。

alterindexidx_bnamerenametoindex_bname3.删除索引index_Bname,将命令写在实验报告中。

dropindexindex_bname4.建立“人民邮电出版社”所出版的图书视图V_Pub,视图中包含书号、书名、出版社信息。

grantcreateviewtolatto;createviewv_pubasselectb_id,b_name,publish.*frombook,publishwherebook.p_id=publish.p_idandpubname="人民邮电出版社"5.创建一个借阅统计视图,名为V_Count_1,包含读者的借书证号和总借阅本数,要求该视图为只读。

createviewv_count_1(借书证号,总借阅本数)asselectr_id,count(*)fromborrowgroupbyr_idwithreadonly6.创建一个借阅统计视图,名为V_Count_2,包含借阅总本数大于两本的读者号和总借阅本数。

createviewv_count_2(读者号,总借阅本数)asselectr_id,count(*)fromborrowgroupbyr_idhavingcount(*)=27.修改视图V_Pub,要求增加图书的单价信息,并且该视图进行的更新操作只涉及“人民邮电出版社”。

createorreplaceviewv_pubasselectb_id,b_name,price,publish.*frombook,publishwherepublish.p_id=book.p_idandpubname="人民邮电出版社"withcheckoption8.删除视图V_Pub。

dropviewv_pub9.创建序列S_BookUser,要求初值为1,序列增量为2,没有最大值限制。

createsequences_bookuserstartwith1incrementby210.修改序列S_BookUser的最大值为1000。

altersequences_bookusermaxvalue100011.新建表Test(UserIDNUMBER,UserName*****2(10)),向表中插入两条数据,其中UserID字段由序列S_BookUser提供,并查看表test是否插入成功。

createtabletest(UserIDNUMBER,UserName*****2(10))insertintotestvalues(s_bookuser.nextval,"tom")12.删除序列S_BookUser。

dropsequences_bookuser【任务8】常量、变量和系统函数1.编写程序实现将Reader表中借书证号为“***-*****01”的读者的姓名赋值给变量r_name,并输出该变量的值。

declarer_namevarchar2(20);beginselectR_nameintor_namefromreaderwherer_id="***-*****01";dbms_output.put_line("***-*****001读者名为:

"||r_name);end;2.输出当前系统日期月份和年份。

begindbms_output.put_line(extract(monthfromsysdate));dbms_output.put_line(extract(yearfromsysdate));end;3.使用字符函数统计字符串“SQLServer2008”的长度。

begindbms_output.put_line(length("SQLServer2008"));end;4.使用函数删除字符串“SQLServer2008”左右两端的窗格并输出。

begindbms_output.put_line(trim("SQLServer2008"));end;【任务9】流程控制语句1.编写PL/SQL语句块,求2~500之间的素数和。

declaresnumber:

=0;flagboolean:

=true;beginforiin2..500loopforjin2..i-1loopifmod(i,j)=0thenflag:

=false;endif;endloop;ifflagthens:

=s+i;endif;flag:

=true;endloop;dbms_output.put_line("sumis"||s);end;2.编写PL/SQL语句块,使用IF语句求出3个数中最大的数。

declareinumber;jnumber;knumber;maxnumnumber;begini:

=12;j:

=9;k:

=7;maxnum:

=i;ifmaxnum

="j;"endif;ifmaxnum

="18;n:

=8;l:

=14;">nandmlthenmaxnum:

=m;elsifnlthenmaxnum:

=n;elsemaxnum:

=l;endif;dbms_output.put_line("maxis"||maxnum);END;3.编写PL/SQL语句块,要求使用循环结构来计算10!

declaresnumber:

=1;beginforiin1..10loops:

=s*i;endloop;dbms_output.put_line("sumis"||s);end;4.查询图书中有没有英语书和SQLServer方面的书,如果有则统计其册数。

declaree_countnumber:

=0;o_countnumber:

=0;cursorbookcurisselectb_namefrombook;bname_bookbook.b_name%type;beginifbookcur%isopen=falsethenopenbookcur;endif;fetchbookcurintobname_book;whilebookcur%foundloopifinstr(bname_book,"英语")0thene_count:

=e_count+1;elsifinstr(bname_book,"SQLSERVER")0theno_count:

=o_count+1;endif;fetchbookcurintobname_book;exitwhenbookcur%notfound;endloop;closebookcur;dbms_output.put_line("英语书的数量为:

"||e_coun

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 其它

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1