DELIMITER $$
DROP PROCEDURE IF EXISTS `dinv`.`sp_InsertCustomer`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_InsertCustomer`(
IN vCustId varchar(120),
IN vName Varchar(16),
IN vMobileNumber Varchar(120),
IN vEmail Varchar(500),
IN vCountry varchar(120),
IN vCity VarChar(80),
IN vZipCode Date,
IN vAddress VarChar(80),
IN vRemarks Date,
IN vCreatedBy Varchar(80),
IN vParam Varchar(50)
)
BEGIN
SET @type = vParam;
IF @type="Save" THEN
Insert into customer(CustID,Name,MobileNumber,EmailId,Country,City,ZipCode,Address,Remarks,CreatedBy,CreatedDate)
values(vCustId,vName,vMobileNumber,vEmail,vCountry,vCity,vZipCode,vAddress,vRemarks,vCreatedBy,GetDate());
ELSE
Update customer Set Name=vName,MobileNumber=vMobileNumber,EmailId=vEmail,Country=vCountry,City=vCity,ZipCode=vZipCode,Address=vAddress,
Remarks=vRemarks,ModifiedBy=vCreatedBy,ModifiedDate=GetDate() where CustID=vCustId;
END IF;
DELIMITER ;
错误代码:1064 您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在第23行的''附近使用正确的语法
嗨,我是mysql的新手并试图用if else条件写程序,但是得到错误,所以plz帮助.. 感谢
答案 0 :(得分:1)
您没有END
语句来终止BEGIN
阻止。
基本上你有这个结构
DELIMITER $$
-- DROP STATEMENT
CREATE PROCEDURE sp_InsertCustomer(..parameter list..)
BEGIN
SET @type = vParam;
IF @type = "Save" THEN -- mysql accepts double quotes and single quotes
-- INSERT STATEMENT
ELSE
-- UPDATE STATEMEMT
END IF;
END $$ -- <<== lacking part
DELIMITER ;