当前位置:网站首页>Database Experiment 7 stored procedure experiment
Database Experiment 7 stored procedure experiment
2022-04-23 21:45:00 【Hebuter-Rui】
1. The experiment purpose
Master the design and use of database .
2. The contents and requirements of the experiment
Definition of stored procedure , Stored procedure running , The stored procedure is renamed , Stored procedure deletion .
3. The experimental steps
(1) Define a stored procedure proc1, Update all orders ( Discount price including tax ) Total price of , Execute the stored procedure .
Source code :
CREATE PROCEDURE proc1 ()
BEGIN
UPDATE orders
SET totalprice = (
SELECT
SUM(
extendedprice * (1 - discount) * (1 + tax)
)
FROM
lineitem
WHERE
orders.orderkey = lineitem.orderkey
);
END;
CALL proc1 ()
(2) Define a stored procedure proc2, Update the for a given order ( Discount price including tax ) Total price of , Execute the stored procedure .
Source code :
CREATE PROCEDURE proc2 (IN okey INT)
BEGIN
UPDATE orders
SET totalprice = (
SELECT
SUM(
extendedprice * (1 - discount) * (1 + tax)
)
FROM
lineitem
WHERE
orders.orderkey = lineitem.orderkey
AND orders.orderkey = okey
);
END;
CALL proc2 (11)
(3) Define a stored procedure proc3, Update all orders for a customer ( Discount price including tax ) The total price , Execute the stored procedure .
Source code :
CREATE PROCEDURE proc3 (IN cname CHAR(25))
BEGIN
DECLARE L_custkey INT;
SELECT
custkey INTO L_custkey
FROM
customer
WHERE
NAME = cname;
UPDATE orders
SET totalprice = (
SELECT
SUM(
extendedprice * (1 - discount) * (1 + tax)
)
FROM
lineitem
WHERE
orders.orderkey = lineitem.orderkey
AND orders.custkey = L_custkey
);
END;
CALL proc3 (' Kong Zhen ')
(4) Define a stored procedure proc4, Update all orders for a customer ( Discount price including tax ) Total price and output the total price , Execute the stored procedure .
Source code :
CREATE PROCEDURE proc4 (
IN cname CHAR (25),
OUT price_total NUMERIC (10, 2)
)
BEGIN
DECLARE L_custkey INT;
SELECT
custkey INTO L_custkey
FROM
customer
WHERE
NAME = cname;
UPDATE orders
SET totalprice = (
SELECT
SUM(
extendedprice * (1 - discount) * (1 + tax)
)
FROM
lineitem
WHERE
orders.orderkey = lineitem.orderkey
AND orders.custkey = L_custkey
);
SELECT
SUM(totalprice) INTO price_total
FROM
orders
WHERE
custkey = L_custkey
GROUP BY custkey;
END;
CALL proc4 (' Kong Zhen ' ,@p_total);
SELECT
@p_total;
Results screenshots :
(5) Delete stored procedure proc4.
Source code :
DROP PROCEDURE proc4;
版权声明
本文为[Hebuter-Rui]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204200618536782.html
边栏推荐
- Tensorflow realizes gradient accumulation, and then returns
- 从严从重从快 上海全面加强疫情期间食品安全监管
- Resolve the "chromedriver executable needs to be in path" error
- Chrome 94 introduces the controversial idle detection API, which apple and Mozilla oppose
- C reads excel specific data into specific columns of DataGridView
- Unit function expansion
- Tencent cloud has two sides in an hour, which is almost as terrible as one side..
- ERP function_ Financial management_ Basic concepts of Finance
- Deep understanding of modern mobile GPU (continuously updating)
猜你喜欢
管道和xargs
Online timing flow chart making tool
C winfrom DataGridView click on the column header can not automatically sort the problem
opencv应用——以图拼图
Amazon and epic will be settled, and the Microsoft application mall will be opened to third parties
Minecraft 1.12.2模组开发(四十三) 自定义盾牌(Shield)
Deno 1.13.2 发布
DW basic tutorial (I)
MySQL 回表
Subcontracting of wechat applet based on uni app
随机推荐
管道和xargs
Presto on spark supports 3.1.3 records
Reference of custom message in ROS function pack failed
Chrome 94 introduces the controversial idle detection API, which apple and Mozilla oppose
Sqlserver edits data in the query interface (similar to Oracle's edit and ROWID)
[leetcode refers to offer 42. Maximum sum of continuous subarrays (simple)]
ROS learning notes - tutorial on the use of ROS
Norm normalization in tensorflow and pytorch of records
小米手机全球已舍弃“MI”品牌,全面改用“xiaomi”全称品牌
[leetcode refers to offer 18. Delete the node of the linked list (simple)]
How Axure installs a catalog
IOT design and development
Ali has another "against the sky" container framework! This kubernetes advanced manual is too complete
Thinking after learning to type
Solve importerror: cannot import name 'imread' from 'SciPy misc‘
[leetcode refers to the maximum profit of offer 63. Stock (medium)]
Deep understanding of modern mobile GPU (continuously updating)
Centralized record of experimental problems
JS merge duplicate data in array object
thinkphp5+数据大屏展示效果