MySql:使用concat不起作用,为什么?

MySql:使用concat不起作用,为什么?,mysql,substring,concat,Mysql,Substring,Concat,我有一个疑问: update sales_flat_quote set customer_email = (concat(select substring(md5(rand()) from 1 for 20), '@example.com')); 它给了我这个错误:3你的SQL语法有错误;请查看与MySQL服务器版本对应的手册,以了解在第6行SQL1.sql 6 1的“”附近使用的正确语法。我想用static@example.com字符串连接子字符串select的结果 这个问题怎么了 谢谢 从

我有一个疑问:

update sales_flat_quote set customer_email = (concat(select substring(md5(rand()) from 1 for 20), '@example.com'));
它给了我这个错误:3你的SQL语法有错误;请查看与MySQL服务器版本对应的手册,以了解在第6行SQL1.sql 6 1的“”附近使用的正确语法。我想用static@example.com字符串连接子字符串select的结果

这个问题怎么了

谢谢

从1中为20选择子字符串(md5(rand())
返回结果集,而不是字符串

正确的方法是
updatesales\u flat\u quote set customer\u email=(concat(substring(md5(rand())from 1 for 20),'@example.com');
选择substring(md5(rand())from 1 for 20
返回结果集,而不是字符串


正确的方法是
updatesales\u flat\u quote set customer\u email=(concat(substring(md5(rand())从1到20),“@example.com”);

要使用subselect,必须将其括在括号内:

update sales_flat_quote set customer_email = concat(
        (select substring(md5(rand()) from 1 for 20)), 
        '@example.com');

请注意,在这种情况下,您不需要使用子选择:
rand()
将为每一行调用。

要使用子选择,必须将其括在括号内:

update sales_flat_quote set customer_email = concat(
        (select substring(md5(rand()) from 1 for 20)), 
        '@example.com');
请注意,在这种情况下,您不需要使用subselect:
rand()
将为每一行调用