标签:
虽然MySQL的存储过程,一般情况下,是不会使用到的,但是在一些特殊场景中,还是有需求的。最近遇到一个sql server向mysql迁移的项目,有一些sql server的存储过程需要向mysql迁移。
例子1
DELIMITER // 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 ;
标签:
原文地址:http://www.cnblogs.com/digdeep/p/4814020.html