delimiter // CREATE PROCEDURE area_pro2 ( IN x INT, OUT alarm_count INT, OUT over_spped INT, OUT over_spped_10 INT, OUT over_spped_20 INT, OUT over_spped_50 INT, OUT untreated INT, OUT processed INT ) BEGIN WITH cte AS ( SELECT organization_id FROM `user` WHERE organization_id = x OR father LIKE CONCAT( COALESCE ( ( SELECT father FROM `user` WHERE organization_id = x ), "" ), x, "-%" ) AND is_del = 0 ) SELECT count( location_alarm.id ) INTO alarm_count, COUNT( CASE WHEN location_alarm.max_speed > location_alarm.speed_limit * 10 THEN 0 END ), count( CASE WHEN location_alarm.max_speed / location_alarm.speed_limit > 11 THEN 0 END ) INTO over_spped_10, count( CASE WHEN location_alarm.max_speed / location_alarm.speed_limit > 12 THEN 0 END ) INTO over_spped_20, count( CASE WHEN location_alarm.max_speed / location_alarm.speed_limit > 15 THEN 0 END ) INTO over_spped_50, count( CASE WHEN location_alarm.alarm_process_id IS NULL THEN 0 END ) INTO untreated, count( location_alarm.alarm_process_id ) INTO processed FROM cte INNER JOIN car ON car.organization_id = cte.organization_id AND car.is_del = 0 INNER JOIN location_alarm ON car.id = location_alarm.car_id; END // 我这个存储过程为什么报错了
时间: 2024-03-13 19:43:43 浏览: 59
CSV.rar_In Writing_as3 csv
你的存储过程报错可能是因为你没有指定 DELIMITER。在你的存储过程中,你使用了分号 (;) 来分隔语句,而这与 MySQL 默认使用的分隔符相同。因此,你需要使用 DELIMITER 命令来改变分隔符。
下面是修改后的代码:
```
DELIMITER //
CREATE PROCEDURE area_pro2 (
IN x INT,
OUT alarm_count INT,
OUT over_spped INT,
OUT over_spped_10 INT,
OUT over_spped_20 INT,
OUT over_spped_50 INT,
OUT untreated INT,
OUT processed INT
)
BEGIN
WITH cte AS (
SELECT
organization_id
FROM
`user`
WHERE
organization_id = x
OR father LIKE CONCAT(
COALESCE((SELECT father FROM `user` WHERE organization_id = x), ''),
x,
'-%'
)
AND is_del = 0
)
SELECT
count(location_alarm.id) INTO alarm_count,
COUNT(CASE WHEN location_alarm.max_speed > location_alarm.speed_limit * 10 THEN 0 END),
count(CASE WHEN location_alarm.max_speed / location_alarm.speed_limit > 11 THEN 0 END) INTO over_spped_10,
count(CASE WHEN location_alarm.max_speed / location_alarm.speed_limit > 12 THEN 0 END) INTO over_spped_20,
count(CASE WHEN location_alarm.max_speed / location_alarm.speed_limit > 15 THEN 0 END) INTO over_spped_50,
count(CASE WHEN location_alarm.alarm_process_id IS NULL THEN 0 END) INTO untreated,
count(location_alarm.alarm_process_id) INTO processed
FROM
cte
INNER JOIN car ON car.organization_id = cte.organization_id
AND car.is_del = 0
INNER JOIN location_alarm ON car.id = location_alarm.car_id;
END//
DELIMITER ;
```
在这里,我们使用了 DELIMITER // 命令来指定新的分隔符,并在存储过程的结尾使用了 END// 来结束存储过程定义。最后,我们使用 DELIMITER ; 命令来将分隔符改回默认值。
阅读全文