1. 創建處理過程scott.graduatePRocess 在【SQLPlus Worksheet】中執行下列PL/SQL代碼,創建處理過程scott.graduateprocess。執行結果如圖9.61所示。 ――――――――――――――――――――――――――――――――――――― /*定義過程參數*/ create or replace procedure scott.graduateprocess( tempzhengzhi in scott.graduate.zhengzhi%type, tempyingyu in scott.graduate.yingyu%type, tempzhuanye1 in scott.graduate.zhuanye1%type, tempzhuanye2 in scott.graduate.zhuanye2%type, tempzhuanye3 in scott.graduate.zhuanye3%type, temptotalscore in scott.result.totalscore%type) as /*定義graduaterecord為記錄型變量,臨時存放通過游標從graduate數據表中提取的記錄*/ graduaterecord scott.graduate%rowtype; /*定義graduatetotalscore為數值型變量,統計總分*/ graduatetotalscore scott.result.totalscore%type; /*定義graduateflag為字符型變量,根據結果放入“落選”或“錄取”,然后寫入數據表result*/ graduateflag varchar2(4); /*定義游標graduatecursor,存放的是所有的graduate數據表中的記錄*/ cursor graduatecursor is select * from scott.graduate; /*定義異常處理errormessage*/ errormessage exception; /*開始執行*/ begin /*打開游標*/ open graduatecursor; /*假如游標沒有數據,激活異常處理*/ if graduatecursor%notfound then raise errormessage; end if; /*游標有數據,指針指向第一條記錄,每執行fetch命令,就自動下移,循環執行到記錄提取完畢為止*/ loop fetch graduatecursor into graduaterecord; /*計算總分*/ graduatetotalscore:=graduaterecord.yingyu+graduaterecord.zhengzhi+graduaterecord.zhuanye1+graduaterecord.zhuanye2 +graduaterecord.zhuanye3; /*判定單科和總分是否滿足錄取要求,若滿足,graduateflag變量值為“錄取”,否則為“落選”*/ if (graduaterecord.yingyu>=tempyingyu and graduaterecord.zhengzhi>=tempzhengzhi and graduaterecord.zhuanye1>=tempzhuanye1 and graduaterecord.zhuanye2>=tempzhuanye2 and graduaterecord.zhuanye3>=tempzhuanye3 and graduatetotalscore>=temptotalscore) then graduateflag:='錄取'; else graduateflag:='落選'; end if; /*當游標數據提取完畢后,退出循環”*/ exit when graduatecursor%notfound; /*向結果數據表result中插入處理后的數據*/ insert into scott.result(bh,xm,lb,zhengzhi,yingyu,zhuanye1,zhuanye2,zhuanye3,totalscore,flag) values(graduaterecord.bh,graduaterecord.xm,graduaterecord.lb,graduaterecord.zhengzhi,graduate record.yingyu,graduaterecord.zhuanye1,graduaterecord.zhuanye2,graduaterecord.zhuanye3,graduat etotalscore,graduateflag); end loop; /*關閉游標*/ close graduatecursor; /*提交結果*/ commit; /*異常處理,提示錯誤信息*/ exception when errormessage then dbms_output.put_line('無法打開數據表'); /*程序執行結束”*/ end; ――――――――――――――――――――――――――――――――――――――――――― 【配套程序位置】:第9章/ creategraduateprocess.sql。