MYSQL导入存储过程时出现错误1064

发布于 2024-09-25 09:03:48 字数 881 浏览 5 评论 0原文

我正在导入一个刚刚从开发服务器导出到生产服务器的存储过程,并且在 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 

I'm importing a stored procedure which I just exported from my development server into my production one and I ran into the following error in 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 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

胡大本事 2024-10-02 09:03:48

用新的分隔符定义包围存储过程代码的主体(例如,从 ; 到 $$)。

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 ;

Surround the body of the stored procedure code with a new definition of the delimiter (e.g., from ; to $$).

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 ;
以可爱出名 2024-10-02 09:03:48

在 mysql 中创建函数不起作用 - 错误 1064 中提出的解决方案完全够了。

问题出在 phpMyAdmin 上。从 mysql 命令行运行效果很好。

Solution presented in Creating functions in mysql doesnt work - Error 1064 suffices completely.

The issue was with phpMyAdmin. Running from the mysql command line worked fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文