條件是程序問題與解析參數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