MYSQL Error 1064 when importing stored procedures
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
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 ;
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.
精彩评论