




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、山東建筑大學(xué) 計(jì)算機(jī)學(xué)院 實(shí)驗(yàn)報(bào)告班級(jí):軟測(cè)143 姓名:劉骎 學(xué)號(hào):20141113089實(shí)驗(yàn)成績(jī): 課程:Oracle 同組者: 實(shí)驗(yàn)日期: 實(shí)驗(yàn)6 PL/SQL程序設(shè)計(jì)1 實(shí)驗(yàn)?zāi)康?1) 掌握PL/SQL程序開發(fā)方法。(2) 掌握存儲(chǔ)過(guò)程、函數(shù)、觸發(fā)器、包的創(chuàng)建于調(diào)用。2 實(shí)驗(yàn)要求(1) 根據(jù)圖書銷售系統(tǒng)業(yè)務(wù)要求創(chuàng)建特定的存儲(chǔ)過(guò)程、函數(shù)、觸發(fā)器。(2) 根據(jù)圖書銷售系統(tǒng)業(yè)務(wù)要求將圖書銷售系統(tǒng)相關(guān)的函數(shù)、存儲(chǔ)過(guò)程封裝到包里。3 實(shí)驗(yàn)步驟以bs用戶登錄BOOKSALES數(shù)據(jù)庫(kù),利用PL/SQL程序編寫下列功能模塊。(1) 創(chuàng)建一個(gè)存儲(chǔ)過(guò)程,輸出不同類型圖書的數(shù)量、平均價(jià)格。SQL creat
2、e or replace procedure proc_category_static 2 as 3 -定義游標(biāo),獲取當(dāng)前有哪些圖書種類 4 cursor c_all_category is select distinct category from books; 5 -圖書的平均價(jià)格 6 v_avg_cost number; 7 begin 8 -保存圖書種類 9 for v_each_category in c_all_category LOOP 10 select avg(retail) into v_avg_cost from books where category=v_each_c
3、ategory.category group by category; 11 dbms_output.put_line(種類為:|v_each_category.category|,平均價(jià)格為:| v_avg_cost); 12 END LOOP; 13 end proc_category_static; 14 /(2) 創(chuàng)建一個(gè)存儲(chǔ)過(guò)程,以客戶號(hào)為參數(shù),輸出該客戶訂購(gòu)的所有圖書的名稱與數(shù)量。create or replace procedure proc_get_orderinfo( 2 p_customer_id customers.customer_id%type) 3 as 4 -聲明
4、游標(biāo)存儲(chǔ)客戶的訂單號(hào) 5 cursor c_orderid is select order_id from orders where customer_id=p_customer_id; 6 v_orderid orders.order_id%type; 7 -聲明游標(biāo)存儲(chǔ)訂單信息 8 cursor c_orderitem is select ISBN, sum(quantity) totalnum from orderitem where order_id=v_orderid group by ISBN; 9 -保存圖書的書名 10 v_title books.title%type; 11
5、12 begin 13 open c_orderid; 14 LOOP 15 fetch c_orderid into v_orderid; 16 exit when c_orderid%NOTFOUND; 17 for v_orderitem in c_orderitem LOOP 18 select title into v_title from books where ISBN=v_orderitem.ISBN; 19 DBMS_OUTPUT.PUT_LINE(p_customer_id|訂購(gòu)|v_title|的數(shù)量是|v_orderitem.totalnum); 20 end LOOP
6、; 21 end LOOP; 22 close c_orderid; 23 end proc_get_orderinfo; 24 /exec proc_get_orderinfoo(1001);(3) 創(chuàng)建一個(gè)存儲(chǔ)過(guò)程,以訂單號(hào)為參數(shù),輸出該訂單中所有圖書的名稱、單價(jià)、數(shù)量。create or replace procedure proc_get_orderinfoo( p_order_id orderitem.order_id%type)as -聲明游標(biāo)存儲(chǔ)訂單號(hào)的ISBN cursor c_ISBN is select ISBN from orderitem where order_id=
7、p_order_id; v_ISBN orderitem.ISBN%type; -聲明游標(biāo)存儲(chǔ)訂單信息 cursor c_orderitem is select ISBN,sum(quantity) totalnum from orderitem where ISBN=v_ISBN ; v_title books.title%type; v_retail books.retail%type;begin open c_ISBN; LOOP fetch c_ISBN into v_ISBN; exit when c_ISBN%NOTFOUND; for v_orderitem in c_order
8、item LOOP select title,retail into v_title,v_retail from books where ISBN=v_orderitem.ISBN; DBMS_OUTPUT.PUT_LINE(p_order_id|v_title|v_retail|v_orderitem.totalnum); end LOOP; end LOOP; close c_ISBN;end proc_get_orderinfoo;/(4) 創(chuàng)建一個(gè)存儲(chǔ)過(guò)程,以出版社名為參數(shù),輸出該出版社出版的所有圖書的名稱、ISBN、批發(fā)價(jià)格、零售價(jià)格信息。create or replace proc
9、edure proc_get_name( p_title books.title%type)as cursor c_orderid is select order_id from orders where customer_id=p_customer_id; v_orderid orders.order_id%type; cursor c_orderitem is select ISBN, sum(quantity) totalnum from orderitem where order_id=v_orderid group by ISBN; v_title books.title%type;
10、begin open c_orderid; LOOP fetch c_orderid into v_orderid; exit when c_orderid%NOTFOUND; for v_orderitem in c_orderitem LOOP select title into v_title from books where ISBN=v_orderitem.ISBN; DBMS_OUTPUT.PUT_LINE(p_customer_id|v_title|的數(shù)量是|v_orderitem.totalnum); end LOOP; end LOOP; close c_orderid;en
11、d proc_get_orderinfo;/set serveroutput ondeclarev_customer number;beginv_customer :=&x;proc_get_orderinfo(v_customer);end;/(5) 創(chuàng)建一個(gè)存儲(chǔ)過(guò)程,輸出每個(gè)客戶訂購(gòu)的圖書的數(shù)量、價(jià)格總額。create or replace procedure proc_category_staticas cursor c_all_category is select distinct category from books; v_sum_cost number;begin for v_e
12、ach_category in c_all_category LOOP select sum(retail) into v_sum_cost from books where category=v_each_category.category group by category; dbms_output.put_line(種類為:|v_each_category.category|,總價(jià)格為:| v_sum_cost); END LOOP;end proc_category_static;/set serveroutput onexec proc_category_static;/(6) 創(chuàng)建
13、一個(gè)存儲(chǔ)過(guò)程,輸出銷售數(shù)量前3名的圖書的信息及銷售名次。create or replace procedure proc_category_staticas cursor c_all_category is select distinct category from books; v_sum_retail number;begin for v_each_category in c_all_category LOOP select sum(cost) into v_sum_retail from books where category=v_each_category.category grou
14、p by category; dbms_output.put_line(種類為:|v_each_category.category|,數(shù)量為:| v_sum_retail); END LOOP;end proc_category_static;/set serveroutput onexec proc_category_static; (7) 創(chuàng)建一個(gè)存儲(chǔ)過(guò)程,輸出訂購(gòu)圖書數(shù)量最多的客戶的信息及訂購(gòu)圖書的數(shù)量。(8) 創(chuàng)建一個(gè)存儲(chǔ)過(guò)程,輸出各類圖書中銷售數(shù)量最多的圖書的信息及銷售的數(shù)量。(9) 創(chuàng)建一個(gè)包,實(shí)現(xiàn)查詢客戶訂購(gòu)圖書詳細(xì)信息的分頁(yè)顯示。create or replace proced
15、ure proc_title_staticas cursor c_all_title is select distinct title from books; v_sum_retail number;begin for v_each_title in c_all_title LOOP select sum(cost) into v_sum_retail from books where title=v_each_title.title group by title; dbms_output.put_line(信息為:|v_each_title.title|,數(shù)量為:| v_sum_retail
16、); END LOOP;end proc_title_static;/(10) 創(chuàng)建一個(gè)包,利用集合實(shí)現(xiàn)圖書銷售排行榜的分頁(yè)顯示。(11) 創(chuàng)建一個(gè)包,包含一個(gè)函數(shù)和一個(gè)過(guò)程。函數(shù)以圖書類型為參數(shù),返回該類型圖書的平均價(jià)格。過(guò)程輸出各種類型圖書中價(jià)格高于同類型圖書平均價(jià)格的圖書信息。create or replace package pkg_bookas function get_book_avgcost(p_book_category BOOKS.category%type) return number; procedure pro_showbook(p_book_category BOOK
17、S.category%type);end;/create or replace package body pkg_bookas function get_book_avgcost(p_book_category BOOKS.category%type) return number as v_ISBN BOOKS.ISBN%type; cursor c_books is select retail from BOOKS where ISBN=v_ISBN; v_sumcost number(6,2):=0; v_count number(6) :=0; v_avgcost number :=0;
18、 v_book_category varchar2(10); begin select ISBN into v_ISBN from BOOKS where category=v_book_category; for v_retail in c_books LOOP v_count:=v_count+1; v_sumcost:= v_sumcost+v_retail.retail; end LOOP; v_avgcost:=v_sumcost/v_count; DBMS_OUTPUT.PUT_LINE(v_book_category| -|v_avgcost); return v_avgcost
19、; end; procedure pro_showbook(p_book_category BOOKS.category%type) as v_book_category varchar2(10); cursor c_books is select * from BOOKS where retail=get_book_avgcost(v_book_category); begin for v_books in c_books loop dbms_output.put_line(v_books.ISBN| |v_books.title| |v_books.author| |v_books.pub
20、date| |v_books.publisher_id| |v_books.retail); end loop; end;end;/set serveroutput ondeclare p_book_category BOOKS.category%type; avgcost number;begin p_book_category:=管理; avgcost:=pkg_book.get_book_avgcost(p_book_category); pkg__showbook(管理);end;/(12) 創(chuàng)建一個(gè)觸發(fā)器,當(dāng)客戶下完訂單后,自動(dòng)統(tǒng)計(jì)該訂單所有圖書價(jià)格總額。create
21、 or replace package order_total_costas v_order_id orders.order_id%type;end;/create or replace trigger trg_before_orderbefore insert on ORDERS for each rowbegin order_total_cost.v_order_id:=:new.order_id;end;/set serveroutput oncreate or replace trigger trg_orderafter insert on ORDERitem declare curs
22、or c_orderitem is select ISBN, quantity from orderitem where order_id=order_total_cost.v_order_id; v_ISBN orderitem.ISBN%type; v_quantity orderitem.quantity%type; v_cost books.cost%type; v_sumcost number(6,2):=0;begin for v_orderitem in c_orderitem LOOP if v_orderitem.quantity 10 then select cost in
23、to v_cost from books where ISBN = v_orderitem.ISBN; DBMS_OUTPUT.PUT_LINE(1-|v_cost|:|v_orderitem.ISBN); elsif v_orderitem.quantity10 then select cost into v_cost from books where ISBN = v_orderitem.ISBN; DBMS_OUTPUT.PUT_LINE(1-|v_cost|v_orderitem.ISBN); elsif v_orderitem.quantity10 then select cost into v_cost from books where ISBN = v_orderitem.ISBN; DBMS_OUTPUT.PUT_LINE(1-|v_cost|v_orderitem.ISBN); elsif v_or
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 初中生相貌負(fù)面身體自我對(duì)抑郁的影響-反芻思維的中介效應(yīng)及干預(yù)研究
- 離職勞動(dòng)關(guān)系解除證明(6篇)
- 描述公園的寫景作文11篇范文
- 醫(yī)院護(hù)理組織管理課件
- 雨中的故事記事抒情結(jié)合類作文(12篇)
- 根管治療見習(xí)要點(diǎn)解析
- 數(shù)字媒體制作人員專業(yè)技能認(rèn)證證明書(8篇)
- 正式離職勞動(dòng)證明(8篇)
- 六年級(jí)觀后感閃閃的紅星觀后感450字11篇
- 2025年寶寶維膚膏項(xiàng)目市場(chǎng)調(diào)查研究報(bào)告
- 危重癥醫(yī)學(xué)概論
- 大規(guī)模模型蒸餾技術(shù)
- 基于AI的自動(dòng)化日志分析與異常檢測(cè)
- 時(shí)序數(shù)據(jù)庫(kù)設(shè)計(jì)詳述
- FPC良率提升持續(xù)改善報(bào)告
- (完整版)產(chǎn)品質(zhì)量保證的措施
- 道路綠化養(yǎng)護(hù)投標(biāo)方案(技術(shù)方案)
- 學(xué)校入股合作的協(xié)議書
- 某大學(xué)2021-2022年《2417客戶關(guān)系管理》期末考試真題及答案(共4套)
- 前程無(wú)憂mat管理能力測(cè)試題庫(kù)35題
- 電力現(xiàn)貨市場(chǎng)基本原理課件
評(píng)論
0/150
提交評(píng)論