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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

数据库系统实训——实验五——存储过程

發布時間:2025/3/15 windows 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 数据库系统实训——实验五——存储过程 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

第一部分:樣例庫的應用
1)Creating Stored Procedures(創建)

CREATE PROCEDURE productpricing( ) BEGINSELECT Avg(prod_price) AS priceaverageFROM products; END; (求出產品的平均價格)


2)Executing Stored Procedures(調用)

CALL productpricing();


3)Dropping Stored Procedures(刪除)

DROP PROCEDURE productpricing;


4)Working with Parameters(帶參的存儲過程)
1)帶輸出參數:

CREATE PROCEDURE productpricing(OUT pl DECIMAL(8,2),OUT ph DECIMAL(8,2),OUT pa DECIMAL(8,2) ) BEGINSELECT Min(prod_price)INTO plFROM products;SELECT Max(prod_price)INTO phFROM products;SELECT Avg(prod_price)INTO paFROM products; END; CALL productpricing(@pricelow,@pricehigh,@priceaverage); SELECT @pricehigh, @pricelow, @priceaverage; (功能:分別返回產品的最高、最低、平均價格,并存入三個變量中,所有MYSQL變量在使用時都必須以@開頭)


2)帶輸入輸出參數:

CREATE PROCEDURE ordertotal(IN onumber INT,OUT ototal DECIMAL(8,2) ) BEGINSELECT Sum(item_price*quantity)FROM orderitemsWHERE order_num = onumberINTO ototal; END;CALL ordertotal(20005, @total); SELECT @total; CALL ordertotal(20009, @total); SELECT @total; (功能:求出某特定訂單號的總金額)


5)Building Intelligent Stored Procedures(創建智能存儲過程)

-- Name: ordertotal -- Parameters: onumber = order number -- taxable = 0 if not taxable, 1 if taxable -- ototal = order total variableCREATE PROCEDURE ordertotal(IN onumber INT,IN taxable BOOLEAN,OUT ototal DECIMAL(8,2) ) COMMENT ‘Obtain order total, optionally adding tax’ BEGIN-- Declare variable for totalDECLARE total DECIMAL(8,2);-- Declare tax percentageDECLARE taxrate INT DEFAULT 6;-- Get the order totalSELECT Sum(item_price*quantity)FROM orderitemsWHERE order_num = onumberINTO total;-- Is this taxable?IF taxable THEN-- Yes, so add taxrate to the totalSELECT total+(total/100*taxrate) INTO total;END IF;-- And finally, save to out variableSELECT total INTO ototal; END;CALL ordertotal(20005, 0, @total); SELECT @total;CALL ordertotal(20005, 1, @total); SELECT @total; (求是否含稅的給定訂單總金額)


6)Inspecting Stored Procedures(檢查存儲過程)
1、

SHOW CREATE PROCEDURE ordertotal; (功能:顯示用于創建一個存儲過程ordertotal的CREATE語句,即定義語句的本身)


2)

SHOW PROCEDURE STATUS LIKE 'ordertotal' ; (功能:獲得當前數據庫中包括何時、何人創建等詳細信息的存儲過程列表,可以限制或指定一個過濾模式,如LIKE關鍵字的使用。)


第二部分:所選課題數據庫的應用
1)Creating Stored Procedures(創建)

CREATE PROCEDURE moviepricing( ) BEGINSELECT Avg(length) AS lengthaverageFROM movies; END; (求出電影的平均時長)


2)Executing Stored Procedures(調用)

CALL moviepricing();


3)Dropping Stored Procedures(刪除)

DROP PROCEDURE moviepricing;


4)Working with Parameters(帶參的存儲過程)
1)帶輸出參數:

CREATE PROCEDURE moviepricing(OUT pl DECIMAL(8,2),OUT ph DECIMAL(8,2),OUT pa DECIMAL(8,2) ) BEGINSELECT Min(length)INTO plFROM movies;SELECT Max(length)INTO phFROM movies;SELECT Avg(length)INTO paFROM movies; END; CALL moviepricing(@movielow,@moviehigh,@movieaverage); SELECT @moviehigh, @movielow, @movieaverage; 語句:(功能:分別返回產品的最高、最低、平均時長,并存入三個變量中,所有MYSQL變量在使用時都必須以@開頭)


2)帶輸入輸出參數:

CREATE PROCEDURE ordertotal(IN onumber INT,OUT ototal DECIMAL(8,2) ) BEGINSELECT Sum(producerC)FROM moviesWHERE length = onumberINTO ototal; END;CALL ordertotal(116, @total); SELECT @total;


5)Building Intelligent Stored Procedures(創建智能存儲過程)

-- Name: ordertotal -- Parameters: onumber = length -- taxable = 0 if not taxable, 1 if taxable -- ototal = order total variableCREATE PROCEDURE ordertotal(IN onumber INT,IN taxable BOOLEAN,OUT ototal DECIMAL(8,2) ) COMMENT 'Obtain order total, optionally adding tax' BEGIN-- Declare variable for totalDECLARE total DECIMAL(8,2);-- Declare tax percentageDECLARE taxrate INT DEFAULT 6;-- Get the order totalSELECT Sum(producerC)FROM moviesWHERE length = onumberINTO total;-- Is this taxable?IF taxable THEN-- Yes, so add taxrate to the totalSELECT total+(total/100*taxrate) INTO total;END IF;-- And finally, save to out variableSELECT total INTO ototal; END;CALL ordertotal(116, 0, @total); SELECT @total;


6)Inspecting Stored Procedures(檢查存儲過程)
1、
SHOW CREATE PROCEDURE ordertotal;
(功能:顯示用于創建一個存儲過程ordertotal的CREATE語句,即定義語句的本身)

2)

SHOW PROCEDURE STATUS LIKE 'ordertotal' ; (功能:獲得當前數據庫中包括何時、何人創建等詳細信息的存儲過程列表,可以限制或指定一個過濾模式,如LIKE關鍵字的使用。)

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的数据库系统实训——实验五——存储过程的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。