DELIMITER $$;DROP PROCEDURE IF EXISTS `sports_shop`.`login`$$CREATE DEFINER=`root`@`localhost` PROCEDURE `login`(in username varchar(40),in userpassword varchar(20),out message varchar(40))
BEGIN
if not exists(select * from client where LoginName=username and Pwd=userpassword)
begin
message = '错误'
endEND$$DELIMITER ;$$
目的就是没这个用户时,输出出错信息,怎么在mysql总是错误呢?

解决方案 »

  1.   

    DELIMITER $$DROP PROCEDURE IF EXISTS `sports_shop`.`login`$$ CREATE DEFINER=`root`@`localhost` PROCEDURE `login`(in username varchar(40),in userpassword varchar(20),out message varchar(40)) 
    BEGIN 
    declare v_i int;
    select count(*) into v_i from client where LoginName=username and Pwd=userpassword;
    if v_i =0 then
     set message = '错误';
    end if;
    END$$ DELIMITER ;
      

  2.   

    你这不是MYSQL的语法!if not exists(select * from client where LoginName=username and Pwd=userpassword)
    这并不被MYSQL支持message = '错误'
    这个也不被支持。
    define xxx int default 0;
    select count(*) into xxx from client where LoginName=username and Pwd=userpassword;
    if xxx =0 then
       set message = '错误';
    建议参考一下mysql的官方文档MySQL官方文档 http://dev.mysql.com/doc/refman/5.1/zh/index.html
    当您的问题得到解答后请及时结贴.
    http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
      

  3.   

    谢谢两位,不过按你们所写的怎么总是提示Undeclared variable: v_i
      

  4.   


    你现在的代码是什么?
    有没有DECLARE v_i INT;
      

  5.   

    DELIMITER $$DROP PROCEDURE IF EXISTS `sports_shop`.`login`$$ CREATE DEFINER=`root`@`localhost` PROCEDURE `login`(in username varchar(40),in userpassword varchar(20),out message varchar(40)) 
    BEGIN 
    declare vi int;
    select count(*) into vi from client where LoginName=username and Pwd=userpassword;
    if vi =0 then
     set message = '错误';
    end if;
    END$$ DELIMITER ;现在代码,v_i被我改成了vi,还是提示Undeclared variable: vi