Error Code 1292 - Truncated incorrect DOUBLE value - MySQL

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

#1292 - Truncated incorrect DOUBLE value:

我没有双值字段或数据!

我花了整整一个小时才想明白!

here is my query

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

这是我的 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
290613 次浏览

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

如果关闭 strict模式,错误将转变为警告。

我也面临着同样的问题。尝试将 varchar (100)列与数字1进行比较。导致1292错误。修正了在1(’1’)附近添加单引号的问题。

谢谢上面的解释

当我收到这个错误时,我相信这是一个错误,但是你应该记住,如果你做一个单独的查询与 SELECT 语句和相同的 WHERE 子句,然后你可以抓取主 ID 的从该 SELECT: SELECT CONCAT(primary_id, ','))语句,并插入到失败的更新查询与条件-> “ WHERE [ main _ ID ] IN ([列表逗号分隔的主 ID 的从 SELECT 语句)”,允许你减轻任何问题是由原始(失败)查询的 WHERE 子句造成的。

就我个人而言,当我在“ WHERE _ _ _ _ IN ([ value here ])”中为值使用引号时,300个预期条目中只有10个受到影响,在我看来,这似乎是一个 bug。

我纠正了这个错误,因为在查询中有一个语法错误或一些不需要的字符,但 MySQL 无法捕捉到它。在更新过程中,我在多个字段之间使用了 and,例如。

update user
set token='lamblala',
accessverion='dummy' and
key='somekey'
where user = 'myself'

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

DR

这也可能是由于将 OR应用于字符串列/字面值造成的。

完整版

对于一个包含视图的简单 INSERT语句,我得到了相同的错误消息:

insert into t1 select * from v1

尽管所有的源和目标列都是 VARCHAR类型的。经过一些调试,我找到了根本原因; 视图中包含这个片段:

string_col1 OR '_' OR string_col2 OR '_' OR string_col3

这可能是 Oracle 自动转换以下代码片段的结果:

string_col1 || '_' || string_col2 || '_' || string_col3

(|| is string concatenation in Oracle). The solution was to use

concat(string_col1, '_', string_col2, '_', string_col3)

取而代之。

在我的例子中,是一个视图(高度嵌套的,视图中的视图)插入导致了 中的错误:

CREATE TABLE tablename AS
SELECT * FROM highly_nested_viewname
;

The workaround we ended up doing was simulating a materialized view (which is really a table) and periodically insert/update it using stored procedures.

Had this issue with ES6 and TypeORM while trying to pass .where("order.id IN (:orders)", { orders }), where orders was a comma separated string of numbers. When I converted to a template literal, the problem was resolved.

.where(`order.id IN (${orders})`);

我见过几个这种错误发生的案例:

1. using the not equals operator != in a where clause with a list of multiple or values

例如:

where columnName !=('A'||'B')

这可以通过使用

where columnName not in ('A','B')

2. missing a comparison operator in an if() function:

select if(col1,col1,col2);

为了选择 col1中的值(如果它存在的话) ,或者在 col2中显示值... ... 这会抛出错误; 可以使用以下方法解决:

select if(col1!='',col1,col2);

如果在表中使用了 检查限制作为字符串字段长度

例如: 检查用户名长度 > = 8

用途:

CHECK (CHAR_LENGTH(username)>=8)

而不是

CHECK (username>=8)

修复检查约束,如果有错误的数据类型比较

如果您没有双值字段或数据,也许您应该尝试禁用 sql 严格模式。

要做到这一点,你必须编辑“ 我的小妹妹”文件位于 MySQL 安装文件夹,找到“设置 SQL 模式为严格”行,并改变以下行:

# Set the SQL mode to strict
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

删除“ STRICT _ TRANS _ TABLES”

# Set the SQL mode to strict
sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

之后,您必须使用 重新启动 MySQL 服务来启用此更改。

To check the change, open the editor an execute this sql sentence:

SHOW VARIABLES LIKE 'sql_mode';

非常重要 : 保存后注意文件格式。将其保存为“ UTF8”,而不是“ TFT8 with BOM”,因为服务将不会重新启动。