【正文】
16/16。end if。(3) 在Course上創(chuàng)建一個(gè)更新觸發(fā)器TR_Course_Upd,對(duì)Course表的課程號(hào)進(jìn)行更新操作,則更新Score表中對(duì)應(yīng)的課程號(hào)。end if。select o into po from course where o=:。po %type。end。(1) 在Student上創(chuàng)建一個(gè)刪除TR_Student_Del,對(duì)Student表進(jìn)行刪除操作,則刪除Score表中對(duì)應(yīng)學(xué)號(hào)的所有記錄;create or replace trigger TR_Student_Del after delete on student referencing new as new old as old for each rowbeginif deleting thendelete from score where sno=:。end。(||||||||||)。loopfetch CUR_VAR INTO stu。cursor CUR_VAR is select * from Student。例83:(存儲(chǔ)過(guò)程) 創(chuàng)建一個(gè)對(duì)學(xué)生姓名進(jìn)行模糊查找的帶參存儲(chǔ)過(guò)程Student_Name。close CUR_AVG。(AvgGrade)。loopfetch CUR_AVG INTO AvgGrade。cursor CUR_AVG is select avg(score) from score group by sno。例82:(存儲(chǔ)過(guò)程) 創(chuàng)建一個(gè)顯示學(xué)生平均成績(jī)的存儲(chǔ)過(guò)程Student_Avg。end。(||||||||||)。loopfetch CUR_VAR INTO stu。cursor CUR_VAR is select * from Student。8. 存儲(chǔ)過(guò)程與觸發(fā)器:例81:(存儲(chǔ)過(guò)程) 創(chuàng)建顯示學(xué)生信息的存儲(chǔ)過(guò)程Student_List。 例74: (修改數(shù)據(jù)庫(kù)表) 刪除成績(jī)表Score的參照完整性約束關(guān)系。例73: (修改數(shù)據(jù)庫(kù)表) 添加成績(jī)表Score的參照完整性約束關(guān)系。 例72: (刪除索引) 刪除索引SC_GRADE。[ 實(shí)驗(yàn)內(nèi)容 ]7.索引與數(shù)據(jù)庫(kù)完整性 例71: (建立索引) 為Score表按課程號(hào)升序、分?jǐn)?shù)降序建立索引,索引名為SC_GRADE。select ame as 課程,ctime as 課時(shí) from course 。select ame as 課程,ctime as 課時(shí) from course 。update course set ctime=70 where ame=39。update course set ctime=80 where ame=39。再次查詢(xún)?nèi)空n程的總學(xué)時(shí)數(shù)。select ame as 課程,ctime as 課時(shí) from course 。select ame as 課程,ctime as 課時(shí) from course 。update course set ctime=70 where ame=39。update course set ctime=80 where ame=39。再次查詢(xún)?nèi)空n程的總學(xué)時(shí)數(shù)。revoke select on student from user1。revoke all on teach from user1。grant select on score to public。grant all on teach to user1。grant select on student to user1 with grant option。5. SQL數(shù)據(jù)控制語(yǔ)句: 例51: (授權(quán)) 給左右鄰近同學(xué)(用戶(hù))授予在表Student上的SELECT權(quán)限,并使這兩個(gè)用戶(hù)具有給其他用戶(hù)授予相同權(quán)限的權(quán)限。drop view student_cs。delete from student_gr。9600639。不能對(duì)含有聚合函數(shù)的視圖進(jìn)行更新操作,因?yàn)楦虏僮鞯慕Y(jié)果是會(huì)反映到基本表上的,而更新聚合函數(shù)無(wú)法得知更新基本表的那個(gè)元件 例48: (視圖更新) 刪除視圖STUDENT_CS中學(xué)號(hào)為 ‘96006’ 的學(xué)生的全部數(shù)據(jù)。觀(guān)察其運(yùn)行結(jié)果并分析原因。 update student_cs set sage=sage+1。 例46: (視圖更新) 利用視圖STUDENT_CS,將學(xué)生年齡增加1歲。男39。0239。CS39。張然39。9600639。 例45: (視圖更新) 利用視圖STUDENT_CS,增加學(xué)生( ‘96006’,‘張然’,‘CS’,‘02’,‘男’,19 )。 例44: (視圖查詢(xún)) 利用視圖STUDENT_GR,求平均成績(jī)?yōu)?8分以上的學(xué)生的學(xué)號(hào)和平均成績(jī)。 例43: (視圖查詢(xún)) 利用視圖STUDENT_CS,求年齡大于19歲的學(xué)生的全部信息。 例42: (建立視圖) 建立由學(xué)號(hào)和平均成績(jī)兩個(gè)字段的視圖STUDENT_GR。create view student_cs as select * from student where sdept=39。實(shí)驗(yàn)三:視圖、授權(quán)控制與事務(wù)處理[ 實(shí)驗(yàn)日期 ] 年 月 日[ 實(shí)驗(yàn)?zāi)康?]通過(guò)實(shí)驗(yàn)進(jìn)一步理解視圖的建立和更新、數(shù)據(jù)庫(kù)的權(quán)限管理和事務(wù)處理功能。 例340 (from子查詢(xún)) 求總成績(jī)排名前五的學(xué)生學(xué)號(hào)和總成績(jī)。00439。 例339: (相關(guān)子查詢(xún)) 求未選修課程004的學(xué)生的姓名。李麗39。 例338:(返回多列的子查詢(xún)) 求與 ‘李麗’ 同系且同齡的學(xué)生的姓名和系。00439。 例337:(子查詢(xún)EXISTS) 求選修了課程004的學(xué)生的姓名和系。MA39。 例336:(子查詢(xún)ALL) 求比數(shù)學(xué)系中全體學(xué)生年齡大的學(xué)生的姓名和系。MA39。 例335:(子查詢(xún)ANY) 求比數(shù)學(xué)系中某一學(xué)生年齡大的學(xué)生的姓名和系。數(shù)據(jù)結(jié)構(gòu)39。 例334:(子查詢(xún)) 求選修了課程名為 ’數(shù)據(jù)結(jié)構(gòu)’ 的學(xué)生的學(xué)號(hào)和姓名。李麗39。 select sname,sno from student where sno not in (select distinct from student right outer join(select distinct sno s from score,course where =) on =s) 例333:(子查詢(xún)) 求與 ‘李麗’ 年齡相同的學(xué)生的姓名和系。)。select sname,sdept,sage from student where sage(select sage from student where sname=39。 select sname,o,score from student st,score sc where =。 and not score between 70 and 90。 select sname,ame,score from student,course,score where = and = and =39。 select sno,o,score from score where sno in(select sno from score group by score,sno having count(*)=1)。) group by sdept,sclass。 select count(sno)as 總?cè)藬?shù),sdept as 系,sclass as 班 from(select * from student where sclass!=39。 例326:(分組查詢(xún)) 求學(xué)生人數(shù)不足3人的系及其相應(yīng)的學(xué)生數(shù)。并給出正確的查詢(xún)語(yǔ)句。 SELECT SNAME,SDEPT,COUNT(*)FROM STUDENT GROUP BY SDEPT。 select count(sno) as 總?cè)藬?shù),avg(sage) as 平均年齡 from student group by sdept,sclass。 select o,avg(score) as 平均成績(jī),sum(score) as 總成績(jī) fro