我正在本地主机 PHPmyAdmin 上创建一个存储过程,但是有一个我找不到的错误
I'm creating a stored procedure on localhost PHPmyAdmin, but there is an error I cannot find
我写了这段代码,但它在第 10 行显示错误。在我的编辑器中,第 10 行是 INSERT INTO employee(Name,EmpCode,Salary)
。下面是我的代码
CREATE PROCEDURE `EmployeeAddOrEdit`(
IN _EmpID INT,
IN _Name varchar(45),
IN _EmpCode varchar(45),
IN _Salary int
)
BEGIN
IF _EmpID=0 THEN
INSERT INTO employee(Name,EmpCode,Salary)
VALUES (_Name,_EmpCode,_Salary);
SET _EmpID=LAST_INSERT_ID();
ELSE
UPDATE employee
SET
Name=_Name,
EmpCode=_EmpCode,
Salary=_Salary
WHERE EmpID=_EmpID;
END IF;
SELECT _EmpID AS 'EmpID';
END
这是错误:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use
near '' at line 10
在 PHPMyAdmin SQL 部分,
set the Delimiter to $$ instead of ;
然后 运行 再次查询。
见图片参考
我写了这段代码,但它在第 10 行显示错误。在我的编辑器中,第 10 行是 INSERT INTO employee(Name,EmpCode,Salary)
。下面是我的代码
CREATE PROCEDURE `EmployeeAddOrEdit`(
IN _EmpID INT,
IN _Name varchar(45),
IN _EmpCode varchar(45),
IN _Salary int
)
BEGIN
IF _EmpID=0 THEN
INSERT INTO employee(Name,EmpCode,Salary)
VALUES (_Name,_EmpCode,_Salary);
SET _EmpID=LAST_INSERT_ID();
ELSE
UPDATE employee
SET
Name=_Name,
EmpCode=_EmpCode,
Salary=_Salary
WHERE EmpID=_EmpID;
END IF;
SELECT _EmpID AS 'EmpID';
END
这是错误:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 10
在 PHPMyAdmin SQL 部分,
set the Delimiter to $$ instead of ;
然后 运行 再次查询。
见图片参考