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


让我们创建一个存储过程。此处,我们正在计算 amount*quantity,即实现数学运算 −

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)

更新于:2019 年 12 月 24 日

734 次浏览

开启你的 职业

通过完成课程获得认证

开始
广告
© . All rights reserved.