我缺乏构建存储过程的经验,并且遇到了这个错误,我无法理解背后的原因:
[2015-09-29 01:01:55] [22001] [1292]数据截断:截断错误的DOUBLE值:' 5609d3e6c89be'
价值' 5609d3e6c89be'是" FlightID"。
我的存储过程代码:
DROP PROCEDURE IF EXISTS initFlight;
CREATE PROCEDURE initFlight (flightid VARCHAR(50))
BEGIN
-- rules, player should only fly if not in jail, not in missions
-- and is in the city the flight will take off from
DECLARE fname VARCHAR(50); -- flight name
DECLARE depart int; -- city number of departure
DECLARE dest int; -- city number of destination
-- assign values to our variables
select flightname, source_airport, destination_airport
into fname, depart, dest
from airport_flights where id = flightID;
-- show in console the variable values for debugging
-- select concat(" fname: ", fname, " depart: ", depart, " dest: ", dest);
-- set players flying means p.live = '-1'
update `[players]` as p set p.live = '-1' where p.id in (
select id from airport_tickets where flight = flightID
) and p.live = depart;
-- insert into alerts a message for players boarding the flight (are in the city of departure)
insert into player_alerts (alert_text, player_id)
select concat("Boarding flight ", fname) as alert_text, p.id as player_id from `[players]` as p
where p.id in (
select id from airport_tickets where flight = flightID
) and p.live = depart;
-- insert into alerts a message for players that missed the flight (are not in the city of departure)
insert into player_alerts (alert_text, player_id)
select concat("You missed flight ", fname) as alert_text, id as player_id from `[players]` as p
where p.id in (
select id from airport_tickets where flight = flightID
) and p.live != depart;
-- stop sales
update airport_flights set selling_tickets = 0 where id = flightID;
END;
call initFlight('5609d3da016bf');
这里发生了什么?为什么我的"字符串"被翻译成双重然后被截断?
airport_flights.id is varchar(50)
airport_flights.source_airport is int(11)
airport_flights.destination_airport is int(11)
airport_tickets.id is varchar(50)
airport_tickets.flight is varchar(50)
airport_tickets.owner_id is int(11)
`[players]`.id is int(11)
`[players]`.live is int(11)
`[players]`.name is varchar(200)
player_alerts.id is int(11)
player_alerts.alert_text is varchar(250)
PS:如果您需要更多信息,请告诉我,批评一如既往欢迎
答案 0 :(得分:0)
经过多次头撞后,我发现问题出现在子查询中,当我想将airport_tickets.owner_id与玩家匹配时,我将airport_tickets.id(varchar)与player.id(int)混合在一起。 ID。
我只是在删除所有内容并将其全部重新编写时才发现这一点,以此来消除任何代码失明(当您的大脑读取它认为代码执行的内容而不是实际编写的内容时)。