该实验是针对数据表jdxx,该数据表有四个字段,分别是省份(sf)、城市(cs)、区县(qxmc)、街道(name)。 建立存储过程 dqxx(in city varchar(10),in district varchar(10)) 输入城市city和区县district的名称,显示乡x、镇z和街道jd、其他的个数 提示:即name字段含有乡、镇、街道及不包含上述选项的个数 调用过程 以长沙市和开福区为参数,调用dqxx过程 以厦门市和同安区为参数,调用dqxx过程
时间: 2023-06-26 19:10:32 浏览: 111
全国城市数据全--省、市、区县
建立存储过程如下:
```
CREATE PROCEDURE dqxx(
IN city VARCHAR(10),
IN district VARCHAR(10)
)
BEGIN
DECLARE x_count INT DEFAULT 0;
DECLARE z_count INT DEFAULT 0;
DECLARE jd_count INT DEFAULT 0;
DECLARE other_count INT DEFAULT 0;
SELECT COUNT(*) INTO x_count FROM jdxx
WHERE city = city AND district = district AND name LIKE '%乡%';
SELECT COUNT(*) INTO z_count FROM jdxx
WHERE city = city AND district = district AND name LIKE '%镇%';
SELECT COUNT(*) INTO jd_count FROM jdxx
WHERE city = city AND district = district AND name LIKE '%街道%';
SELECT COUNT(*) INTO other_count FROM jdxx
WHERE city = city AND district = district AND name NOT LIKE '%乡%' AND name NOT LIKE '%镇%' AND name NOT LIKE '%街道%';
SELECT CONCAT('乡: ', x_count, ', 镇: ', z_count, ', 街道: ', jd_count, ', 其他: ', other_count) AS result;
END
```
调用过程如下:
```
CALL dqxx('长沙市', '开福区');
CALL dqxx('厦门市', '同安区');
```
注意:在调用存储过程时,需要使用CALL关键字。
阅读全文