From dadcb3d4d33748ed4fbd58e92361dcc934175b75 Mon Sep 17 00:00:00 2001 From: mba1398 <26516464+mba1398@users.noreply.github.com> Date: Mon, 7 Apr 2025 15:23:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20ch05=5FSQL=E9=AB=98?= =?UTF-8?q?=E7=BA=A7=E5=A4=84=E7=90=86.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ch05_SQL高级处理.md | 50 +++++++++++++++------------------------------ 1 file changed, 17 insertions(+), 33 deletions(-) diff --git a/ch05_SQL高级处理.md b/ch05_SQL高级处理.md index a775c96..95afa47 100644 --- a/ch05_SQL高级处理.md +++ b/ch05_SQL高级处理.md @@ -235,56 +235,40 @@ CREATE - 查询 下面的示例显示了一个简单的存储过程,给定一个国家代码,计算在 `world` 数据库的城市表中出现的该国家的城市数量。使用 `IN` 参数传递国家代码,使用 `OUT` 参数返回城市计数: ```sql -mysql> DELIMITER // -mysql> DROP PROCEDURE IF EXISTS citycount // -Query OK, 0 rows affected (0.01 sec) +DELIMITER // -mysql> CREATE PROCEDURE citycount (IN country CHAR(3), OUT cities INT) +DROP PROCEDURE IF EXISTS citycount // + +CREATE PROCEDURE citycount (IN country CHAR(3), OUT cities INT) BEGIN SELECT COUNT(*) INTO cities FROM world.city WHERE CountryCode = country; END// -Query OK, 0 rows affected (0.01 sec) -mysql> DELIMITER ; -mysql> CALL citycount('CHN', @cities); -- cities in China -Query OK, 1 row affected (0.01 sec) +DELIMITER ; - -> SELECT @cities; -+---------+ -| @cities | -+---------+ -| 363 | -+---------+ -1 row in set (0.04 sec) +CALL citycount('CHN', @cities); -- cities in China + +SELECT @cities; ``` - 创建表 ```SQL -mysql> use world; -Database changed -mysql> DELIMITER $$ -mysql> CREATE DEFINER=`root`@`localhost` PROCEDURE `product_test`() +use world; + +DELIMITER $$ + +CREATE DEFINER=`root`@`localhost` PROCEDURE `product_test`() BEGIN #Routine body goes here... CREATE TABLE product_test like shop.product; END$$ -Query OK, 0 rows affected (0.01 sec) -mysql> DELIMITER; -mysql> call `product_test`(); -Query OK, 0 rows affected (0.04 sec) +DELIMITER; -mysql> show tables; -+-----------------+ -| Tables_in_world | -+-----------------+ -| city | -| country | -| countrylanguage | -| product_test | -+-----------------+ -4 rows in set (0.02 sec) +call `product_test`(); + +show tables; ``` - 插入数据 ```SQL