Error Code: 1424. Recursive stored functions and triggers are not allowed

Viewed 16
Delimiter //
create function fn_calcular_subtotal(_cantidad int, _precio int) 
returns int
BEGIN
declare subtotal int;
set subtotal= (select sum(_Cantidad*_Precio) from producto join detalle_pedido on ID_Producto = Producto where ID_Producto = Producto);
return fn_calcular_subtotal();
END//
1 Answers

I think you meant to return subtotal. At the moment you are invoking the function again in the return statement.

Delimiter //
create function fn_calcular_subtotal(_cantidad int, _precio int) 
returns int
BEGIN
declare subtotal int;
set subtotal= (select sum(_Cantidad*_Precio) from producto join detalle_pedido on ID_Producto = Producto where ID_Producto = Producto);
return subtotal;  /* <---------------------- */
END//
Related