我有一个存储函数,需要在表格前加上数值
如何在SELECT中使用@packages_plu等?
CREATE DEFINER=`fs01`@`%` FUNCTION `pack_isp`(fk_packages_id INT , c TEXT) RETURNS decimal(10,2)
BEGIN
DECLARE p DECIMAL(10,2);
SET p = 0;
SET @packages_plu=CONCAT(c,'_packages_plu');
SET @products= CONCAT(c,'_products');
SET @packages= CONCAT(c,'_packages');
SELECT
SUM(d.quantity * p.price_each_inc)
INTO p FROM
1_packages_plu d
LEFT JOIN
1_products p ON d.fk_products_id = p.id
LEFT JOIN
1_packages g ON g.id = fk_packages_id
WHERE
d.fk_packages_id = fk_packages_id;
RETURN p;
END
答案 0 :(得分:0)
你可以使用准备好的陈述来做到这一点,它有点hacky但是有效。
请参阅此处的手册: http://dev.mysql.com/doc/refman/5.6/en/sql-syntax-prepared-statements.html