I want to make some function in phpmyadmin
DELIMITER //
CREATE FUNCTION total_bayar (order_id char(10))
RETURNS double
DETERMINISTIC
BEGIN
DECLARE dist double;
SET dist = SELECT sum(qty * price) FROM detail_masakan WHERE order_id = order_id;
RETURN dist;
END//
DELIMITER ;
Query SQL: Dokumentasi
CREATE FUNCTION total_bayar (order_id char(10))
RETURNS double
DETERMINISTIC
BEGIN
DECLARE dist double;
SET dist = SELECT sum(qty * price) FROM detail_masakan WHERE order_id = order_id;
RETURN dist;
END
MySQL says: Dokumentasi
#1064 – You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘SELECT sum(qty * price) FROM detail_masakan WHERE order_id = order_id;
RETURN’ at line 6
2
Answers
Appears it didn’t like your use of the SET command. Use SELECT…INTO instead.
You need parentheses for the subquery:
However, this still won’t do what you want, because the variable names are messed up — and will get confused with the column names.
I would suggest: