delimiter //
create procedure aa()
begin
declare x varchar(20);
set x='hjl';
if length(x)=3 then
select x;
endif;
end
//为什么老报错??

解决方案 »

  1.   

    select x;
    你什么意思?
      

  2.   

    这不是mysql里面的显示打印吗?
      

  3.   

    mysql> create procedure aa()
        -> begin
        -> declare x varchar(20);
        -> set x='a';
        -> if length(x)=3 then
        -> select x;
        -> end if;
        -> end
        -> //
    Query OK, 0 rows affected (0.00 sec)
      

  4.   

    mysql> create procedure aa()
        -> begin
        -> declare x varchar(20);
        -> set x='hjl';
        -> if length(x)=3 then
        -> select x;
        -> endif;
        -> end
        -> //
    ERROR 1064 (42000): 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 ';
    end' at line 7

    mysql>错误提示很清楚了,你的第七行endif;。有问题,然后你就可以看一下MYSQL手册中的语法,就立即明白 end if