在 MySQL 存储过程中执行数学运算?

mysqlmysqli database更新于 2024/10/10 0:12:17

让我们创建一个存储过程。在这里,我们计算金额*数量,即执行数学运算−

mysql> delimiter //
mysql> create procedure calculation_proc(amount int,quantity int)
     begin
     select amount,quantity,(amount*quantity) as Total;
     end
     //
Query OK, 0 rows affected (0.00 sec)
mysql> delimiter ;

现在您可以使用 CALL 命令调用存储过程 −

mysql> call calculation_proc(250,3);

这将产生以下输出 −

+--------+----------+-------+
| amount | quantity | Total |
+--------+----------+-------+
|    250 |        3 |   750 |
+--------+----------+-------+
1 row in set (0.00 sec)
Query OK, 0 rows affected (0.00 sec)

相关文章


有用资源