你如何在 MySQL 中将回车附加到一个值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9314689/
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
How do you append a carriage return to a value in MySQL?
提问by jhowe
I'm importing some restaurant information and have found that I'm missing the type of cuisine in the description field. How do I append a carriage return to a value?
我正在导入一些餐厅信息,但发现描述字段中缺少美食类型。如何将回车附加到值?
This is what I have so far; I want the cuisine to go in on a new line:
这是我到目前为止所拥有的;我希望菜系在一个新的线上:
select concat(field_id_20, '\r', 'french') from table
回答by Michael Berkowski
If you want a new line, then you're looking for a \n
newline rather than a carriage return.
如果您想要\n
换行,那么您正在寻找换行符而不是回车符。
SELECT CONCAT_WS('\n', field_id_20, 'french');
CONCAT_WS()
concatentates all subsequent arguments with the first argument. So you could add multiple lines this way by doing:
CONCAT_WS()
将所有后续参数与第一个参数连接起来。因此,您可以通过以下方式添加多行:
SELECT CONCAT_WS('\n', field_id_20, 'french', 'german', 'indian');
Outputs:
CurrentValueFrom field_id_20
french
german
indian