语法中的mysql循环错误

时间:2013-07-03 17:41:36

标签: mysql loops label

我正在使用以下语法使用Heidisql在mysql中使用简单循环。

BEGIN
loop_label:  LOOP
                     IF  @number_title  > @max THEN
                          **LEAVE  loop_label;**
                     END  IF;
select @number_title as number_distinct_title,count(*) as total from (
select count(distinct ctitle), customer_id
FROM table
GROUP BY customer_id
HAVING count(distinct ctitle)=@number_title 
ORDER BY customer_id) as total ;
SET @number_title = @number_title + 1;
END LOOP
END

我在 LEAVE loop_label;

时遇到语法错误

有人可以帮忙吗?

由于

1 个答案:

答案 0 :(得分:0)

在MySQL中定义触发器或过程时,通常需要临时更改分隔符,因为触发器/过程中的语句必须以“;”结束。

将完整的块放在“ - /”和“/”中,你应该很好

--/
BEGIN
loop_label:  LOOP
                 IF  @number_title  > @max THEN
                      **LEAVE  loop_label;**
                 END  IF;
 select @number_title as number_distinct_title,count(*) as total from (
 select count(distinct ctitle), customer_id
 FROM table
 GROUP BY customer_id
 HAVING count(distinct ctitle)=@number_title 
 ORDER BY customer_id) as total ;
 SET @number_title = @number_title + 1;
 END LOOP
END
 /

Here

找到