2017-08-25 85 views
0

我试图测试出包含在此SQL语句随机的电子邮件地址字符串 判断strcmp()函数:为什么这个strcmp()语法在mysql-5.7中给我一个错误?

INSERT IGNORE INTO possible_duplicate_email 
-> (human_id, email_address_1, email_address_2, entry_date) 
-> VALUES(LAST_INSERT_ID(), '[email protected]', 
            '[email protected]') 
-> WHERE ABS(STRCMP('[email protected]', '[email protected]')) = 1; 

然后我得到这个错误信息:

ERROR 1064 (42000): You have an error in your SQL syntax; 
check the manual that corresponds to your MySQL server version for the 
right syntax to use near 'WHERE ABS(STRCMP('[email protected]', 
'[email protected]')) = 1' at line 4 

我读过从mysql-5.7参考手册 的strcmp()文档中,尝试了一个简单的SELECT语句,以查看strcmp()返回的数值为 ,值为-1,0,1,它包含IGNORE选项 给SQ L声明以便通过错误继续。有人可以向我解释为什么在WHERE子句中运行strcmp()时出现此错误?

+0

'INSERT'语句不**具有'WHERE'子句,除非执行'INSERT ... SELECT'语句,那么查询的'SELECT'部分可以使用'WHERE'子句。 [见此](https://dev.mysql.com/doc/refman/5.7/en/insert.html)获取更多信息。 –

+0

非常感谢! –

回答

0

感谢Paul T.,答案是:

INSERT语句没有WHERE子句,除非做一个INSERT ... SELECT语句,然后在查询的SELECT部分​​可以使用WHERE子句。

相关问题