Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Hinzufügen eines Zeilenumbruchs in MySQL INSERT INTO-Text

Wenn Sie mit einem SQL-Befehl einverstanden sind, der sich über mehrere Zeilen erstreckt, dann oedos Vorschlag ist der einfachste:

INSERT INTO mytable (myfield) VALUES ('hi this is some text
and this is a linefeed.
and another');

Ich hatte gerade eine Situation, in der es vorzuziehen war, die SQL-Anweisung alle in einer Zeile zu haben, also fand ich heraus, dass eine Kombination aus CONCAT_WS() und CHAR() hat bei mir funktioniert.

INSERT INTO mytable (myfield) VALUES (CONCAT_WS(CHAR(10 using utf8), 'hi this is some text', 'and this is a linefeed.', 'and another'));