我正在将我刚从开发服务器导出的存储过程导入到我的生产服务器中,并且我在phymyadmin中遇到了以下错误。
SQL query: Documentation
$$ CREATE DEFINER = `devuser`@`localhost` FUNCTION `get_refundable_amount` (
enrol_id INT
) RETURNS double( 10, 2 ) READS SQL DATA BEGIN DECLARE refundable_amount double( 10, 2 ) DEFAULT 0;
SELECT (
sum( P.amount ) - EI.amount
)
INTO refundable_amount
FROM site_payment_processed AS P
INNER JOIN site_user_enroled AS E ON ( P.enrol_id = E.id
AND P.payment_type = 'Refund' )
INNER JOIN site_user_enroled_invoice AS EI ON EI.enrol_id = E.id
WHERE E.id = enrol_id
GROUP BY E.id;
RETURN (
refundable_amount
);
END$$
MySQL said: Documentation
#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 '$
CREATE DEFINER=`devuser`@`localhost` FUNCTION `get_refundable_amount`' at line 1
答案 0 :(得分:3)
使用分隔符的新定义(例如,从;到$$)围绕存储过程代码的主体。
DELIMITER $$
CREATE DEFINER = `devuser`@`localhost` FUNCTION `get_refundable_amount` (
enrol_id INT
) RETURNS double( 10, 2 ) READS SQL DATA BEGIN DECLARE refundable_amount double( 10, 2 ) DEFAULT 0;
SELECT (
sum( P.amount ) - EI.amount
)
INTO refundable_amount
FROM site_payment_processed AS P
INNER JOIN site_user_enroled AS E ON ( P.enrol_id = E.id
AND P.payment_type = 'Refund' )
INNER JOIN site_user_enroled_invoice AS EI ON EI.enrol_id = E.id
WHERE E.id = enrol_id
GROUP BY E.id;
RETURN (
refundable_amount
);
END $$
DELIMITER ;
答案 1 :(得分:0)
Creating functions in mysql doesnt work - Error 1064中提供的解决方案就足够了。
问题出在phpMyAdmin上。从mysql命令行运行工作正常。