我试图从mssql转换存储过程 - > MySQL的。并且坚持使用可选参数,因为mysql不支持它。对于mssql,参数初始化为NULL,并且基于p_Mode值调用不同的语句。是否有解决方法? 我转换的MySQL存储过程是这样的:
CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_tblLogin`(
p_LoginId int/* =null */,
p_LoginName varchar(100)/* =null */,
p_Email varchar(100)/* =null */,
p_Username varchar(20)/* =null */,
p_Password varchar(20)/* =null */,
p_Rights int/* =null */,
p_Mode varchar(25))
BEGIN
IF (p_Mode='Insert') THEN
IF NOT EXISTS (SELECT * FROM tblLogin WHERE Username=p_Username)
THEN
INSERT INTO tblLogin(LoginName,Email,Username,Password,Rights,ModifiedDate) VALUES(p_LoginName,p_Email,p_Username,p_Password,p_Rights,now());
END IF;
END IF;
IF (p_Mode='View')
THEN
SELECT * FROM tblLogin;
END IF;
IF (p_Mode='ViewByID')
THEN
SELECT * FROM tblLogin WHERE LoginId = p_LoginId;
END IF;
IF (p_Mode='ChkLogin')
THEN
SELECT * FROM tblLogin WHERE Username = p_Username and Password = p_Password;
END IF;
IF (p_Mode='Update')
THEN
UPDATE tblLogin
SET `LoginName` = p_LoginName
,`Email` = p_Email
,`Username` = p_Username
,`Password` = p_Password
,`Rights` = p_Rights
,`ModifiedDate` = now()
WHERE LoginId = p_LoginId;
END IF;
IF (p_Mode='Delete')
THEN
DELETE FROM `tblLogin` WHERE LoginId = p_LoginId;
END IF;
END