大家帮我看下 我的存储过程哪儿错了 
  CREATE   PROCEDURE v_competition_getlabels(f1 varchar(20))
begin
      if(f1='voc_id') then
              select distinct voc_id,rps_voc from viw_competition_ana;
       else if(f1='cop_id') then
             select distinct cop_id,cop_name from viw_competition_ana;
             end if;
     end if;
end;
Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line4我在front下能执行啊,怎么在PHPMYADMIN和SQLYOG下都报这个错呢,谢谢

解决方案 »

  1.   

    else if(f1='cop_id') then改成elseif(f1='cop_id') then手册中语法说明如下
    IF search_condition THEN statement_list
        [ELSEIF search_condition THEN statement_list] ...
        [ELSE statement_list]
    END IF
    MySQL官方文档 http://dev.mysql.com/doc/refman/5.1/zh/index.html
      

  2.   

    elseif 不能连着写,这样是错误的,我试过的
      

  3.   

    没试没有问题,估计是你没有设置 delimiter
    mysql> delimiter //
    mysql>  CREATE   PROCEDURE v_competition_getlabels(f1 varchar(20))
        -> begin
        ->      if(f1='voc_id') then
        ->              select distinct voc_id,rps_voc from viw_competition_ana;
        ->       else if(f1='cop_id') then
        ->             select distinct cop_id,cop_name from viw_competition_ana;
        ->             end if;
        ->     end if;
        -> end;
        -> //
    Query OK, 0 rows affected (0.00 sec)mysql> delimiter ;
    mysql>