简体   繁体   中英

Mysql stored procedure problems

I am new to MySQL stored procedures. I wrote login validation, but it will not work.

CREATE PROCEDURE `Login_validation`(
IN `Username` VARCHAR(50),
IN `password` VARCHAR(50)) 
  LANGUAGE SQL
  NOT DETERMINISTIC
  CONTAINS SQL
  SQL SECURITY DEFINER
  COMMENT ''
   BEGIN

        IF EXISTS(SELECT * FROM user_details where FIRSTNAME=@Username) THEN
            BEGIN
                    IF EXISTS(SELECT * FROM user_details where FIRSTNAME=@Username and Password=@password) THEN
                         BEGIN
                             SELECT 'SUCCESS' STATUSDISCRTIPTION, '100' STATUSCODE;
                      END;
                    ELSE
                            BEGIN
                                    SELECT 'USERNAME AND PASSWORD NOT MATCHING' STATUSDISCRTIPTION, '101' STATUSCODE;
                            END;
                    END IF; 
            END;
        ELSE
                BEGIN
                            SELECT 'USERNAME NOT EXISTS' STATUSDISCRTIPTION , '101' STATUSCODE;
                END;
        END IF;
    END 

This my stored procedure, I got SELECT 'USERNAME NOT EXISTS' STATUSDISCRTIPTION , '101' STATUSCODE; this output only. if loop not working.

call Login_validation('Malathi','123456')

malathi name is there in table. What is the problem?

The notation @username if for user variables, not to be confused with stored procedures parameters.

Use where FIRSTNAME = Username

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM