错误代码1292 - 截断不正确的DOUBLE值 - Mysql

Mik*_*ike 56 mysql truncated mysql-error-1292

我不确定这个错误是什么!

#1292 - Truncated incorrect DOUBLE value: 
Run Code Online (Sandbox Code Playgroud)

我没有双值字段或数据!

我浪费了整整一个小时试图解决这个问题!

这是我的查询

INSERT INTO call_managment_system.contact_numbers 
    (account_id, contact_number, contact_extension, main_number, created_by)
SELECT
    ac.account_id,
    REPLACE(REPLACE(REPLACE(REPLACE(ta.phone_number, '-', ''), ' ', ''), ')', ''),'(','') AS Phone,
    IFNULL(ta.ext, '') AS extention,
    '1' AS MainNumber,
    '2' AS created_by
FROM 
    cvsnumbers AS ta
    INNER JOIN accounts AS ac ON ac.company_code = ta.company_code
WHERE 
    LENGTH(REPLACE(REPLACE(REPLACE(REPLACE(ta.phone_number, '-', ''), ' ', ''), ')', ''),'(','') ) = 10
Run Code Online (Sandbox Code Playgroud)

这是我的show create table,用于表格的结果

CREATE TABLE `contact_numbers` (  
    `number_id` int(10) unsigned NOT NULL AUTO_INCREMENT,  
    `account_id` int(10) unsigned NOT NULL DEFAULT '0',  
    `person_id` int(11) NOT NULL DEFAULT '0',  
    `contact_number` char(15) NOT NULL,  
    `contact_extension` char(10) NOT NULL DEFAULT '',  
    `contact_type` enum('Primary','Direct','Cell','Fax','Home','Reception','Office','TollFree') NOT NULL DEFAULT 'Primary',  
    `contact_link` enum('Account','PDM','Other') NOT NULL DEFAULT 'Account',  
    `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '0 = inactive, 1=active', 
    `main_number` tinyint(1) NOT NULL DEFAULT '0' COMMENT '1 = main phone number',  
    `created_on` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,  
    `created_by` int(11) NOT NULL,  
    `modified_on` datetime DEFAULT NULL,  
    `modified_by` int(11) NOT NULL DEFAULT '0',  
    PRIMARY KEY (`number_id`),  
    KEY `account_id` (`account_id`),  
    KEY `person_id` (`person_id`)
) ENGINE=InnoDB AUTO_INCREMENT=534 DEFAULT CHARSET=utf8
Run Code Online (Sandbox Code Playgroud)

Bar*_*mar 110

此消息表示您正在尝试比较WHEREor ON子句中的数字和字符串.在您的查询中,唯一可能发生的地方是ON ac.company_code = ta.company_code; 要么确保它们具有类似的声明,要么使用显式CAST将数字转换为字符串.

如果关闭strict模式,则错误应变为警告.

  • 谢谢你 扩展:可以通过多种方式触发这种情况。就我而言,它使用正则表达式从字符串中提取整数,并将其与整数进行比较。奇怪的是,当我只使用SELECT语句时,一切都很好:从t1上的t1内部联接t2中选择xxxx。id= substr(value,locate(':',tagvalue)+1)一旦我将其转换为INSERT。 ..SELECT,错误已触发。 (3认同)
  • 哇,多么误导性的错误信息。谢谢你的帮助。你是对的。我需要将 `DB::table('contacts')->where('attendance', $int) ->update(["attendance" => $string]);` 更改为 `DB::table('contacts ')->where('出勤', '' . $int) ->update(["出勤" => $string]);` (2认同)

小智 7

我更正了此错误,因为查询中存在语法错误或某些不需要的字符,但MySQL无法捕获它。我and在更新期间在多个字段之间使用,例如

update user 
set token='lamblala', 
    accessverion='dummy' and 
    key='somekey' 
where user = 'myself'
Run Code Online (Sandbox Code Playgroud)

上面的查询中的问题可以通过替换and为逗号(,)来解决

  • 谢谢,这不是一个大问题,但有时小问题会变成大问题 (2认同)

For*_*ner 5

我面临着同样的问题。试图将varchar(100)列与数字1进行比较。导致1292错误。通过在1('1')附近加上单引号来解决。

感谢您上面的解释


Fra*_*itt 5

TL; DR

这也可能是由于应用于OR字符串列/文字引起的。

完整版本

对于INSERT涉及视图的简单语句,我收到了相同的错误消息:

insert into t1 select * from v1
Run Code Online (Sandbox Code Playgroud)

尽管所有源列和目标列都是VARCHAR. 经过一番调试,我找到了根本原因;该视图包含以下片段:

string_col1 OR '_' OR string_col2 OR '_' OR string_col3
Run Code Online (Sandbox Code Playgroud)

这大概是以下来自 Oracle 的片段的自动转换的结果:

string_col1 || '_' || string_col2 || '_' || string_col3
Run Code Online (Sandbox Code Playgroud)

||是 Oracle 中的字符串连接)。解决方案是使用

concat(string_col1, '_', string_col2, '_', string_col3)
Run Code Online (Sandbox Code Playgroud)

反而。