




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、山東建筑大學(xué) 計算機(jī)學(xué)院 實驗報告班級:軟測143 姓名:劉骎 學(xué)號:20141113089實驗成績: 課程:Oracle 同組者: 實驗日期: 實驗6 PL/SQL程序設(shè)計1 實驗?zāi)康?1) 掌握PL/SQL程序開發(fā)方法。(2) 掌握存儲過程、函數(shù)、觸發(fā)器、包的創(chuàng)建于調(diào)用。2 實驗要求(1) 根據(jù)圖書銷售系統(tǒng)業(yè)務(wù)要求創(chuàng)建特定的存儲過程、函數(shù)、觸發(fā)器。(2) 根據(jù)圖書銷售系統(tǒng)業(yè)務(wù)要求將圖書銷售系統(tǒng)相關(guān)的函數(shù)、存儲過程封裝到包里。3 實驗步驟以bs用戶登錄BOOKSALES數(shù)據(jù)庫,利用PL/SQL程序編寫下列功能模塊。(1) 創(chuàng)建一個存儲過程,輸出不同類型圖書的數(shù)量、平均價格。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 -圖書的平均價格 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|,平均價格為:| v_avg_cost); 12 END LOOP; 13 end proc_category_static; 14 /(2) 創(chuàng)建一個存儲過程,以客戶號為參數(shù),輸出該客戶訂購的所有圖書的名稱與數(shù)量。create or replace procedure proc_get_orderinfo( 2 p_customer_id customers.customer_id%type) 3 as 4 -聲明
4、游標(biā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)存儲訂單信息 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|訂購|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)建一個存儲過程,以訂單號為參數(shù),輸出該訂單中所有圖書的名稱、單價、數(shù)量。create or replace procedure proc_get_orderinfoo( p_order_id orderitem.order_id%type)as -聲明游標(biāo)存儲訂單號的ISBN cursor c_ISBN is select ISBN from orderitem where order_id=
7、p_order_id; v_ISBN orderitem.ISBN%type; -聲明游標(biāo)存儲訂單信息 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)建一個存儲過程,以出版社名為參數(shù),輸出該出版社出版的所有圖書的名稱、ISBN、批發(fā)價格、零售價格信息。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)建一個存儲過程,輸出每個客戶訂購的圖書的數(shù)量、價格總額。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|,總價格為:| v_sum_cost); END LOOP;end proc_category_static;/set serveroutput onexec proc_category_static;/(6) 創(chuàng)建
13、一個存儲過程,輸出銷售數(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)建一個存儲過程,輸出訂購圖書數(shù)量最多的客戶的信息及訂購圖書的數(shù)量。(8) 創(chuàng)建一個存儲過程,輸出各類圖書中銷售數(shù)量最多的圖書的信息及銷售的數(shù)量。(9) 創(chuàng)建一個包,實現(xiàn)查詢客戶訂購圖書詳細(xì)信息的分頁顯示。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)建一個包,利用集合實現(xiàn)圖書銷售排行榜的分頁顯示。(11) 創(chuàng)建一個包,包含一個函數(shù)和一個過程。函數(shù)以圖書類型為參數(shù),返回該類型圖書的平均價格。過程輸出各種類型圖書中價格高于同類型圖書平均價格的圖書信息。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)建一個觸發(fā)器,當(dāng)客戶下完訂單后,自動統(tǒng)計該訂單所有圖書價格總額。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. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 項目工程造價培訓(xùn)課件
- 兒童多動癥的健康教育
- 部隊反邪教課件
- 高效節(jié)能電機(jī)項目經(jīng)濟(jì)效益和社會效益分析報告(范文)
- 2025年會計、審計及稅務(wù)服務(wù)項目發(fā)展計劃
- 新解讀《建筑信息模型(BIM)應(yīng)用標(biāo)準(zhǔn) DBJ-T 36-069-2021》解讀
- 2025年壬基酚聚氧乙烯醚項目建議書
- 細(xì)胞生物學(xué)總結(jié)
- 2025年霍爾汽車點火系統(tǒng)項目合作計劃書
- 2025年花畫工藝品合作協(xié)議書
- 教師進(jìn)企業(yè)實踐三方協(xié)議書
- 施工現(xiàn)場隱患圖片識別合集
- 山西省建設(shè)工程計價依據(jù)
- 煤礦在用安全設(shè)備檢測檢驗制度
- GB/T 24632.2-2009產(chǎn)品幾何技術(shù)規(guī)范(GPS)圓度第2部分:規(guī)范操作集
- GB/T 20428-2006巖石平板
- GB/T 11363-1989釬焊接頭強(qiáng)度試驗方法
- 內(nèi)調(diào)焦準(zhǔn)距式望遠(yuǎn)系統(tǒng)光學(xué)設(shè)計2022年
- 核磁共振的發(fā)展史課件
- 切紙機(jī)安全操作規(guī)程標(biāo)準(zhǔn)范本
- 國家開放大學(xué)2022秋法理學(xué)形考1-4參考答案
評論
0/150
提交評論