mysql concat函数 [英] mysql concat function

查看:52
本文介绍了mysql concat函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我concat($name, $surname)时,有没有一种方法可以使用我的sql而不是php在$name $surname之间放置一个空格,所以当我得到结果时,它会格式化得更干净一些?

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?

非常感谢

推荐答案

您可以将字符串文字与字段连接在一起,以便在要连接的字段之间的字符串中添加空格字符.

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.

使用此:

 CONCAT(name, " ", surname)

MySQL手册上对此功能进行了非常清楚的记录. CONCAT()功能的页面.

This functionality is documented quite clearly on the MySQL manual page for the CONCAT() function.

还有 CONCAT_WS函数,它允许您指定要在传递给函数的其他每个字段之间使用的分隔符.如果您以相同的方式连接两个以上的字段,则此功能可能比在每个字段之间重复分隔符更干净.

There is also the CONCAT_WS function which 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.

例如,如果要添加中间名字段,则可以使用此功能仅指定一次分隔符:

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)

这篇关于mysql concat函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆