MySQL MySQL中的字符串连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5975958/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 19:51:06  来源:igfitidea点击:

String concatenation in MySQL

mysqlmysql-workbenchconcat

提问by Roshan

I am using MySQL and MySQL Workbench 5.2 CE. When I try to concatenate 2 columns, last_nameand first_name, it doesn't work :

我正在使用 MySQL 和 MySQL Workbench 5.2 CE。当我尝试连接 2 列last_name和时first_name,它不起作用:

select first_name + last_name as "Name" from test.student

回答by Eugene Yarmash

MySQL is different from most DBMSs use of +or ||for concatenation. It uses the CONCATfunction:

MySQL 不同于大多数 DBMS 使用+||用于连接。它使用CONCAT函数:

SELECT CONCAT(first_name, " ", last_name) AS Name FROM test.student

As @eggyal pointed out in comments, you can enable string concatenation with the ||operator in MySQL by setting the PIPES_AS_CONCATSQL mode.

正如@eggyal 在评论中指出的那样,您可以||通过设置PIPES_AS_CONCATSQL 模式来启用与MySQL 中的运算符的字符串连接。

回答by ADW

Try:

尝试:

select concat(first_name,last_name) as "Name" from test.student

or, better:

或更好:

select concat(first_name," ",last_name) as "Name" from test.student

回答by Harry Joy

Use concat()function instead of +like this:

使用concat()函数而不是+这样:

select concat(firstname, lastname) as "Name" from test.student

回答by Vithun

That's not the way to concat in MYSQL. Use the CONCAT function Have a look here: http://dev.mysql.com/doc/refman/4.1/en/string-functions.html#function_concat

这不是在 MYSQL 中连接的方式。使用 CONCAT 函数看看这里:http: //dev.mysql.com/doc/refman/4.1/en/string-functions.html#function_concat