我有一个存储过程,不断给我错误的答案。我问过程返回汽车保险的价值。我运行这个程序,给我所有的汽车保险费,但如果我第四次运行它,它会给我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
@Galz它的一个PHP应用程序,存储过程可以完成作业 – imohd23