-1
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 条件编写程序,但出现错误,所以请帮忙..谢谢

4

1 回答 1

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 ;
于 2013-04-25T15:43:28.667 回答