SQL说我在第3行的''附近有语法错误。请帮助
我的目标是计算药品价格总和
这是我来自phpmyadmin的SQL代码:
CREATE PROCEDURE spMEDICATION_FEE(IN PatientID CHAR(9))
BEGIN
DECLARE Sum2 INT;
DECLARE Sum3 INT;
SET Sum2 = (
SELECT SUM(MPRICE)
FROM USES_EXAM INNER JOIN MEDICATION ON USES_EXAM.MID = MEDICATION.MID
WHERE PID_OUT = PatientID);
SET Sum3 = (
SELECT SUM(MPRICE)
FROM USES_TREAT INNER JOIN MEDICATION ON USES_TREAT.MID = MEDICATION.MID
WHERE PID_IN = PatientID);
IF Sum2 IS NULL THEN
SET Sum2 = 0;
IF Sum3 IS NULL THEN
SET Sum3 = 0;
SELECT Sum2+ Sum3 AS 'Total fee';
END
最佳答案
如果使用phpmyadmin的SQL选项卡运行此查询,则应定义定界符而不是;
。例如,尝试以下操作:
DELIMITER $$
paste your create procedure code here
$$
关于mysql - 创建存储过程phpmyadmin,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49999776/