【发布时间】:2017-03-16 04:56:13
【问题描述】:
我有一个不断给我错误答案的存储过程。我要求程序返回汽车保险的价值。我运行该程序并给我汽车保险费的总额,但如果我第 4 次运行它,它会给我 ageRange 选择语句值。 我把代码移到了一个新的过程中,但还是一样。
我的代码
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `cal_motor_qoute`(in
coverID int , in dob date,
in sumMotor double , out QMsg varchar(200))
BEGIN
declare policy_cover , total , insRatio, ageExtra double;
declare ageRange int;
declare price_list varchar(200);
SELECT DATEDIFF(NOW(),dob) / 365.25 AS ageRange from dual;
if (coverID = 1) then
set policy_cover = 0.002;
elseif (coverID = 2) then
set policy_cover = 0.0025;
elseif (coverID = 3) then
set policy_cover = 0.003;
elseif (coverID = 4) then
set policy_cover = 0.0035;
end if;
if ( ageRange < 25) then
set ageExtra = 0.0005;
else
set ageExtra = 0.000;
end if;
set insRatio = policy_cover + ageExtra;
set total = (sumMotor * insRatio )* 10;
set QMsg = concat('total Premium is: ',total);
select @QMsg;
END
请帮忙..
【问题讨论】:
-
问题:为什么这是在存储过程中而不是在应用程序代码中完成的?
-
@Galz 是一个 php 应用程序,存储过程可以完成这项工作
标签: mysql database stored-procedures procedure