【问题标题】:Stored procedure : Data truncation: Truncated incorrect DOUBLE value存储过程:数据截断:截断不正确的 DOUBLE 值
【发布时间】:2015-09-29 00:18:11
【问题描述】:

我缺乏构建存储过程的经验,并且遇到了这个我无法理解背后原因的错误:

[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:如果您需要更多信息,请告诉我,我们一如既往地欢迎批评

【问题讨论】:

  • 如果你把球员表也放上去会有帮助。
  • 来自stackoverflow.com/questions/26743197/…这是引发的那些非常糟糕的错误之一,可能与实际问题没有任何关系。知道过程中的哪个查询收到错误了吗?
  • 现在添加了播放器字段。至于出错的查询,我不知道,这些查询是一一进行的,然后组合到存储过程中,有没有办法调试这个?

标签: mysql stored-procedures


【解决方案1】:

经过多次摸索后,我发现问题出在子查询中,当我想将 airport_tickets.owner_id 与 player 匹配时,我将 airport_tickets.id (varchar) 与 player.id (int) 混合在一起。 ID。

我只是在删除所有内容并将其全部重写以作为消除任何代码盲点的一种措施时才发现这一点(当您的大脑阅读它认为代码所做的而不是实际编写的内容时)。

【讨论】:

    猜你喜欢
    • 2015-08-07
    • 1970-01-01
    • 2015-02-23
    • 1970-01-01
    • 2020-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-28
    相关资源
    最近更新 更多