【正文】
ere empno in(select distinct mgr from ))。(23)select * from t1, t2 where = and in(select deptno from group by deptno having avg(sal)2000) 習(xí)題一、二、1.D 2. B 3. CE 4. A 5. B1.loop循環(huán)實(shí)現(xiàn):declarei number default 1。s number default 0。beginloops:=s+i。i:=i+1。exit when i100。end loop。(39。和是: 39。||s)。end。whlie循環(huán)實(shí)現(xiàn):declarei number default 1。s number default 0。beginwhile i=100 loops:=s+i。i:=i+1。end loop。(39。和是: 39。||s)。end。for循環(huán)實(shí)現(xiàn):declares number default 0。beginfor i in 1..100 loops:=s+i。end loop。(39。和是: 39。||s)。end。2.顯示游標(biāo)的for循環(huán):declarecursor cur1 is select ename,sal from 。beginfor rec in cur1 loop(||39。 39。||)。end loop。end。隱式游標(biāo)的for循環(huán):beginfor rec in (select ename,sal from ) loop(||39。 39。||)。end loop。end。 習(xí)題一、選擇題1. A 2. C 3. B 4. D 5. A二、編程題1.步驟一:sqlplus system/abcdefalter user scott account unlock。connect scott/tiger。grant select on emp to system。connect system/abcdef。步驟二:創(chuàng)建存儲(chǔ)過程set serveroutput oncreate or replace procedure p1(id in %type)iscursor c1 is select * from where deptno=id。 beginfor rec in c1 loop(||39。 39。||||39。 39。||)。end loop。end。步驟三:執(zhí)行存儲(chǔ)過程execute p1(10)。2.步驟一:授權(quán)connect scott/tiger。grant update on emp to system。步驟二:創(chuàng)建函數(shù)connect system/abcdef。create or replace function f1return numberiscursor c2 is select * from for update。rows number default 0。a number(7,2)。beginselect avg(sal) into a from 。for rec in c2 loopif a thenupdate set sal=sal+200 where current of c2。rows:=rows+1。end if。end loop。return rows。end。步驟三:調(diào)用函數(shù):begin(f1)。end。 第二種寫法:create or replace function fun2 return number is begin update set sal=sal+200 where sal(select avg(sal) from )。 return sql%rowcount。 end。 /三、簡答題創(chuàng)建與調(diào)用存儲(chǔ)過程或函數(shù)時(shí),應(yīng)事先授予相應(yīng)的權(quán)限: 首先創(chuàng)建存儲(chǔ)過程應(yīng)授予create procedure的權(quán)限。 用戶調(diào)用其他用戶所創(chuàng)建的存儲(chǔ)過程時(shí),應(yīng)事先授予對該過程的execute權(quán)限。 如果對某表進(jìn)行增、刪、查、改的操作時(shí),應(yīng)授予insert、 delete、update、select的顯示權(quán)限。