在MySQL INSERT INTO文本中添加换行符 [英] Adding a line break in MySQL INSERT INTO text
问题描述
有人可以告诉我如何在MySql表中输入的文本中添加新行吗?
Could someone tell me how to add a new line in a text that I enter in a MySql table?
我尝试在使用INSERT INTO
语句输入的行中使用'\n'
,但'\n'
仍按原样显示.
I tried using the '\n'
in the line I entered with INSERT INTO
statement but '\n'
is shown as it is.
实际上,我已经在MS Access中创建了一个包含一些数据的表. MS Access用'\n'
添加新行.我正在将MS Access表数据转换为MySql.但是,当我转换时,'\n'
被忽略,并且当我在PHP表单上的MySql表中显示它时,所有文本都显示在一行中.
Actually I have created a table in MS Access with some data. MS Access adds new line with '\n'
. I am converting MS Access table data into MySql . But when I convert, the '\n'
is ignored and all the text is shown in one single line when I display it from MySql table on a PHP form.
有人可以告诉我MySQL如何在文本中添加新行吗?等待回复,谢谢!!
Can anyone tell me how MySQL can add a new line in a text? Awaiting response, thanks!!
推荐答案
If you're OK with a SQL command that spreads across multiple lines, then oedo's suggestion is the easiest:
INSERT INTO mytable (myfield) VALUES ('hi this is some text
and this is a linefeed.
and another');
我只是希望将SQL语句全部放在一行上,所以我发现 CHAR()
为我工作.
I just had a situation where it was preferable to have the SQL statement all on one line, so I found that a combination of CONCAT_WS()
and CHAR()
worked for me.
INSERT INTO mytable (myfield) VALUES (CONCAT_WS(CHAR(10 using utf8), 'hi this is some text', 'and this is a linefeed.', 'and another'));
这篇关于在MySQL INSERT INTO文本中添加换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!