简体   繁体   中英

Error #1064 in stored procedure in mysql

if cant to understand my english is because my english is bad.... i will try to explain my problem as best as possible.

I try to create a stored procedure in mysql (phpmyadmin) but i have this error:

#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 line 3

This is the code of stored procedure:

CREATE PROCEDURE `sp_user_insert` (IN `sp_email` varchar(255), IN `sp_password` text, IN `sp_role` int)
BEGIN
    DECLARE `sp_encrypted_password` text;
    SET `sp_encrypted_password` = SELECT MD5(`sp_encrypted_password`);
    INSERT INTO `user`( `user_email`, `user_password`, `user_role_id`) VALUES ( `sp_email`, `sp_encrypted_password`, `sp_role`);
END

And this is the code of the table user:

CREATE TABLE IF NOT EXISTS `user` (
  `user_id` int(11) NOT NULL AUTO_INCREMENT,
  `user_email` varchar(255) NOT NULL,
  `user_password` text NOT NULL,
  `user_role_id` int(11) NOT NULL,
  PRIMARY KEY (`user_id`)
);

PD: I'm sorry, my english is bad :C

See if this helps, you shouldn't need the SELECT to get the MD5 hash.

CREATE PROCEDURE `sp_user_insert` (IN `sp_email` varchar(255), IN `sp_password` text, IN `sp_role` int)
BEGIN
    DECLARE `sp_encrypted_password` text;
    SET `sp_encrypted_password` = MD5(`sp_encrypted_password`);
    INSERT INTO `user`( `user_email`, `user_password`, `user_role_id`) VALUES ( `sp_email`, `sp_encrypted_password`, `sp_role`);
END

This will help. Try once.

DELIMITER $$;
CREATE PROCEDURE sp_user_insert (IN sp_email varchar(255), IN sp_password TEXT, IN sp_role INT(20))
BEGIN
    DECLARE sp_encrypted_password TEXT;
    SELECT MD5(sp_password) INTO sp_encrypted_password;
    INSERT INTO user( user_email, user_password, user_role_id) VALUES ( sp_email, sp_encrypted_password, sp_role);
END

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