条件是程序问题与解析参数mysql的过程 - 在条款
CREATE DEFINER=`root`@`localhost` PROCEDURE `sitter_price`(
in in_hours float,
in age varchar(100),
in no_of_sitters int,
in no_of_days int
)
BEGIN
select
TRUNCATE(sum(price)*in_hours*no_of_days*no_of_sitters,2) as
total_amount
from job_prices jp
join kids_ages ka on ka.id = jp.kids_age_id
where ka.age in(age) and start_hours > in_hours
AND in_hours <= end_hours;
END
的问题是在此过程中是怎么会把年龄为varchar(100),在参数,在第 目前我使用的查询
CALL `usitterz`.`sitter_price`(4.10,'1,2,3,4', 3, 5);
解析但这是错误的,因为在查询读这就像在(“1,2,3,4”),但我想它喜欢 - 在(1,2,3, 4)。
它会像
CREATE DEFINER=`root`@`localhost` PROCEDURE `sitter_price`(
in in_hours float,
in age varchar(100),
in no_of_sitters int,
in no_of_days int
)
BEGIN
select
TRUNCATE(sum(price)*in_hours*no_of_days*no_of_sitters,2) as
total_amount
from job_prices jp
join kids_ages ka on ka.id = jp.kids_age_id
where ka.age in(1,2,3,4) and start_hours > in_hours
AND in_hours <= end_hours;
END
你的做法是好的,但它不是为我工作的答案。给出错误或空结果。 CALL'sitter_price2'(4,'1,2,3,4',1,5); - 给予结果 如果小时数> 4,它给出了错误的结果 CALL'sitter_price2'(5,'1,2,3,4',1,5); - 给零null –
所有重要的是,它产生的SQL字符串正是它应该的。然后它执行它。所以,一个人会在第一步工作,以获得正确的结果。当这是正确的,问题是你的数据。 – Drew
换句话说,EXECUTE执行你想要的查询。如果得到错误的数字,那么你的数据不是你所期望的。 – Drew