mysql concat 函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4494775/
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
mysql concat function
提问by Adamski
when i concat($name, $surname)
, is there a way of putting a space in between the $name $surname
using my sql not php so when i get the result it formats a little cleaner?
当我concat($name, $surname)
,有没有办法在$name $surname
使用我的 sql 而不是 php之间放置一个空格,这样当我得到结果时,它的格式会更清晰一些?
many thanks
非常感谢
回答by AgentConundrum
You can concatenate string literals along with your fields, so you can add a space character in a string between the fields you're concatenating.
您可以将字符串文字与您的字段连接起来,这样您就可以在要连接的字段之间的字符串中添加一个空格字符。
Use this:
用这个:
CONCAT(name, " ", surname)
This functionality is documented quite clearly on the MySQL manual page for the CONCAT()
function.
此功能是记录很清楚的关于对MySQL手册页面CONCAT()
功能。
There is also the CONCAT_WS
functionwhich allows you to specify a separator to be used between each of the other fields passed to the function. If you're concatenating more than two fields in the same way, this function might be considered cleaner than repeating the separator between each field.
还有一个CONCAT_WS
函数允许您指定要在传递给该函数的每个其他字段之间使用的分隔符。如果您以相同的方式连接两个以上的字段,则该函数可能被认为比在每个字段之间重复分隔符更简洁。
For example, if you wanted to add a middle name field, you could use this function to specify the separator only once:
例如,如果您想添加一个中间名字段,您可以使用此函数仅指定一次分隔符:
CONCAT_WS(" ", first_name, middle_name, surname)
回答by Brad Christie
Just add a space in there.
只需在其中添加一个空格。
SELECT CONCAT(name,' ',surname) AS full_name FROM table;
EDIToops, bad spelling there... ;p
编辑哎呀,那里拼写不好...;p
回答by Sam
Use this, no version dependencies
使用这个,没有版本依赖
concat(name,Char(32),venue)
回答by Shivling
after trying this i tried to do this
尝试过这个之后,我试着这样做
concat(name, _utf8 ' ' ,name1)
回答by kayima marvin
Hey i had the same problem and this is what i used and it really worked out great
嘿,我遇到了同样的问题,这就是我使用的,而且效果很好
CONCAT(column1," ",column2) the issue is you add physical space in between the double courts("") using the space bar on your keyboard and then thats it
CONCAT(column1," ",column2) 问题是您使用键盘上的空格键在双场 ("") 之间添加物理空间,然后就是这样
回答by Andre
Use CONCAT(name, ' ', surname)
.
使用CONCAT(name, ' ', surname)
.