日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

2013-11-11 Oracle 课堂测试 练习题 例:BULK COLLECT及return table

發(fā)布時間:2025/3/11 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 2013-11-11 Oracle 课堂测试 练习题 例:BULK COLLECT及return table 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
--1) 查詢“計算機(jī)”專業(yè)學(xué)生在“2007-12-15”至“2008-1-8”時間段內(nèi)借書的 --學(xué)生編號、學(xué)生名稱、圖書編號、圖書名稱、借出日期; select s.stuid, s.stuname, b.bid, b.title, bo.t_timefrom borrow bojoin student s on bo.stuid = s.stuidjoin book b on bo.bid = b.bidwhere bo.t_time between to_date('2007-12-15', 'yyyy-mm-dd') andto_date('2008-01-08', 'yyyy-mm-dd') and s.major = '計算機(jī)';--2) 用pl/sql匿名塊實(shí)現(xiàn),查詢所有借過圖書的學(xué)生編號、學(xué)生名稱、專業(yè);(提示:用游標(biāo)) declarecursor c_student isselect * from student;cursor c_borrow isselect * from borrow; begindbms_output.put_line('學(xué)生編號 ' || ' 學(xué)生姓名 ' || ' 專業(yè)');for v_student in c_student loopfor v_borrow in c_borrow loopif v_student.stuid = v_borrow.stuid thendbms_output.put_line(v_student.stuid || ' ' ||v_student.stuname || ' ' ||v_student.major);exit;end if;end loop;end loop; end;--3) 查詢借過作者為“安意如”的圖書的學(xué)生姓名、圖書名稱、借出日期、歸還日期; select s.stuname, b.title, bo.t_time, bo.b_timefrom borrow bojoin student s on bo.stuid = s.stuidjoin book b on bo.bid = b.bidwhere b.author = '安意如';--4) 查詢目前借書但未歸還圖書的學(xué)生名稱及未還圖書數(shù)量; --(要求: 未還圖書數(shù),用函數(shù)實(shí)現(xiàn),并在sql語句中調(diào)用) create or replace type t_borrowlist_object as object(stuid varchar2(20),books number); create or replace type t_borrowlist_table as table of t_borrowlist_object;create or replace function f_borrowlistreturn t_borrowlist_table is v_rs t_borrowlist_table; beginselect t_borrowlist_object(s.stuname, count(*)) BULK COLLECTINTO v_rsfrom borrow bojoin student s on bo.stuid = s.stuidjoin book b on bo.bid = b.bidwhere bo.b_time is nullgroup by s.stuname;return v_rs; end;select * from table(f_borrowlist());--5)用一個存儲過程完成還書功能,輸入?yún)?shù)為學(xué)號和書號,把當(dāng)前日期作為還書日期。 create or replace function f_rebook(v_stuid student.stuid%type,v_bid book.bid%type) return varchar2 isPRAGMA AUTONOMOUS_TRANSACTION;v_flag number;v_borrowid borrow.borrowid%type;v_rs varchar2(200); beginselect count(*)INTO v_flagfrom borrowwhere b_time is nulland stuid = v_stuidand bid = v_bid;if v_flag >= 1 thenselect borrowidINTO v_borrowidfrom borrowwhere b_time is nulland stuid = v_stuidand bid = v_bidand rownum <= 1;v_rs := v_stuid || ' 號同學(xué)還 ' || v_bid || ' 圖書 成功';update borrow set b_time = sysdate where borrowid = v_borrowid;commit;elsev_rs := v_stuid || ' 號同學(xué)還 ' || v_bid || ' 圖書 失敗';end if;return v_rs; end;select * from borrow;select f_rebook('1001', 'B001') from dual;

總結(jié)

以上是生活随笔為你收集整理的2013-11-11 Oracle 课堂测试 练习题 例:BULK COLLECT及return table的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。