MySQL 存储过程
时间:2021-07-01 10:21:17
帮助过:2人阅读
DROP PROCEDURE IF EXISTS loginandreg
//
CREATE PROCEDURE loginandreg(
OUT userId BIGINT,
IN user_Pwd
VARCHAR(
32),
IN user_MobileCode
VARCHAR(
16),
IN user_RegIP
VARCHAR(
16)
)
BEGIN
DECLARE cnt
BIGINT DEFAULT 0;
DECLARE cnt2
BIGINT DEFAULT 0;
DECLARE outid
BIGINT DEFAULT -1;
SELECT COUNT(
*)
INTO cnt
FROM Users u
WHERE u.user_MobileCode
=user_MobileCode;
IF cnt
> 0 THEN
SELECT COUNT(
*)
INTO cnt2
FROM Users u
WHERE u.user_MobileCode
=user_MobileCode
AND u.user_Pwd
=user_Pwd;
IF cnt2
> 0 THEN
SELECT u.userId
INTO outid
FROM Users u
WHERE u.user_MobileCode
=user_MobileCode
AND u.user_Pwd
=user_Pwd LIMIT
1;
ELSE
SELECT -1 INTO outid;
END IF;
SELECT outid
INTO userId;
ELSE
INSERT INTO Users(user_Pwd,user_MobileCode,user_Visibility,user_Level,user_RegTime,
user_RegIP,user_Collecter,user_Collected)
VALUES (user_Pwd,user_MobileCode,
6,
6,NOW(),user_RegIP,
0,
0);
SET userId
=LAST_INSERT_ID();
SELECT userId;
END IF;
END //
DELIMITER ;
MySQL 存储过程
标签: