Home >Database >Mysql Tutorial >How to replace newline character in mysql

How to replace newline character in mysql

青灯夜游
青灯夜游Original
2022-04-18 15:14:2211499browse

In mysql, you can use the char() and REPLACE() functions to replace newline characters; the REPLACE() function can replace the newline characters in the column with a new string, and the newline character can use "char(13 )", the syntax is "replace(field name,char(13),'new string')".

How to replace newline character in mysql

The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.

In mysql, you can use the char() and REPLACE() functions to replace newlines.

  • The REPLACE() function is used to replace, you can replace the newline character in the column with a new string

  • char() is used to represent a newline Character--"char(13)"

char() can not only represent the newline character, but also the carriage return key and horizontal tab character

  • char(9) Horizontal tab character

  • char(13)Enter key

Replace the newline character with a null character (that is, delete the newline character), you can write like this

replace(字段名,char(10),'')

Example: Replace the newline character in the character with a null character

SELECT *, REPLACE(detail, CHAR(10), '') AS 显示替换后的内容

ASCII attached Code table:

How to replace newline character in mysql

REPLACE(), which allows you to replace a string in a column of a table with a new string. The syntax is as follows:

REPLACE(str,old_string,new_string);

The REPLACE() function has three parameters, which replaces the old_string in string with the new_string string.

It is very important that in the REPLACE function, the first parameter is the column name without quotes ("). If you put quotes around a field name like "field_name", the query will Updates the contents of this column to "field_name", resulting in unexpected data loss.

The REPLACE function does not support regular expressions, so if you need to use pattern replacement from an external library you will need to use a MySQL user-defined function (UDF) Text string.

[Related recommendations: mysql video tutorial]

The above is the detailed content of How to replace newline character in mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn