我正在努力熟悉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'
答案 0 :(得分:0)
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错误消息不是很棒吗?