当前位置:网站首页>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
边栏推荐
- JS prototype and prototype chain
- The computer is out of power. How did I pass the terrible interview of Tencent cloud?
- Subcontracting of wechat applet based on uni app
- A solution of C batch query
- MySQL 回表
- [leetcode refers to the maximum profit of offer 63. Stock (medium)]
- South Korea may ban apple and Google from offering commission to developers, the first in the world
- Oracle updates the data of different table structures and fields to another table, and then inserts it into the new table
- C, print the source program of beautiful bell triangle
- DW basic tutorial (I)
猜你喜欢

Express③(使用Express编写接口、跨域有关问题)
![[leetcode refers to the substructure of offer 26. Tree (medium)]](/img/53/b34ed5f46706f80bc1a9fcdb1481ae.png)
[leetcode refers to the substructure of offer 26. Tree (medium)]

MySQL 回表

Prim、Kruskal

DeNO 1.13.2 release

Is rust more suitable for less experienced programmers?
![[※ leetcode refers to offer 48. The longest substring without repeated characters (medium)]](/img/fa/99b64267fd890c6c40847548f077b3.png)
[※ leetcode refers to offer 48. The longest substring without repeated characters (medium)]
![[leetcode refers to offer 21. Adjust the array order so that odd numbers precede even numbers (simple)]](/img/63/1701a93f91f792195a74edfb99fe18.png)
[leetcode refers to offer 21. Adjust the array order so that odd numbers precede even numbers (simple)]

Deep analysis of C language pointer (Part I)

C winfrom DataGridView click on the column header can not automatically sort the problem
随机推荐
CUDA, NVIDIA driver, cudnn download address and version correspondence
Use 3080ti to run tensorflow GPU = 1 X version of the source code
Leetcode-279-complete square number
DW basic course (II)
pytorch 1.7. The model saved by X training cannot be loaded in version 1.4 or earlier
Opencv application -- jigsaw puzzle
Thread safe sigleton (singleton mode)
Xiaomi mobile phone has abandoned the "Mi" brand all over the world and switched to the full name brand of "Xiaomi"
How to use the project that created SVN for the first time
Assertionerror: invalid device ID and runtimeerror: CUDA error: invalid device ordinal
IOT design and development
Database experiment I database definition and data import
[leetcode sword finger offer 58 - I. flip word order (simple)]
Express③(使用Express编写接口、跨域有关问题)
如何发挥测试策略的指导性作用
Prim、Kruskal
Oracle intercepts special characters
从严从重从快 上海全面加强疫情期间食品安全监管
Introduce structured concurrency and release swift 5.5!
Google tries to use rust in Chrome