我试图熟悉MySQL并感到沮丧。

我正在尝试创建一个功能...

use mystuff;
DELIMITER $$
create PROCEDURE spUpdateCodeTable(
   IN mcodeID INT,
   IN mtableCode CHAR(5),
   IN mDescription VARCHAR(100),
   IN mCode CHAR(5),
   IN mgroupCode CHAR(5),
   IN mt1 VARCHAR(100),
   IN mt2 VARCHAR(100),
   IN mt3 VARCHAR(100))
BEGIN
   UPDATE codeTable SET
      tableCode =mtableCode,
      Description=mDescription,
      Code=mCode,
      groupCode=mgroupCode,
      t1=mt1,
      t2=mt2,
      t3=mt3,
      chaDate=NOW()
   WHERE codeID = mcodeID;

   IF (ROW_COUNT() < 1)
   BEGIN
      INSERT INTO codeTable (tableCode,Description,Code,groupCode,t1,t2,t3,createDate)
      VALUES (mtableCode,mDescription,mCode,mgroupCode,mt1,mt2,mt3,NOW());
   END;
END$$
DELIMITER ;


当我只有UPDATE部分时,该过程编译良好,但是一旦添加插入四行(从IF(ROW_COUNT()....开始),我就开始获取...。

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near'BEGIN INSERT INTO codeTable (tableCode, Description, Code, groupCode,t1,t2,t' at line 23'

最佳答案

就像@Phil所说的那样,您会想要...

IF (ROW_COUNT() < 1) THEN
  INSERT INTO codeTable (tableCode,Description,CODE,groupCode,t1,t2,t3,createDate)
  VALUES (mtableCode,mDescription,mCode,mgroupCode,mt1,mt2,mt3,NOW());
END IF;


而不是你所拥有的。

存储过程的MySQL错误消息不是很好吗?

10-04 15:41