Get the App
SLTechnology News&Howtos  ›  Database  › 

How to replace newline characters with mysql

Shulou Source: shulou.com Published: 2022-05-31 10:48:36 09月19日 Update

Today, I would like to share with you the relevant knowledge of how mysql replaces line breaks. The content is detailed and the logic is clear. I believe most people still know too much about this, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.

In mysql, you can use the char () and REPLACE () functions to replace newline characters; the REPLACE () function can replace newline characters in columns with new strings, which can be expressed as "char (13)" with the syntax "replace (field name, char (13), 'new string')".

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 newline characters.

The REPLACE () function is used to replace the newline character in the column with a new string.

Char () is used to indicate the newline character-"char (13)"

Char () can represent not only newline characters, but also carriage returns and horizontal tabs.

Char (9) horizontal tabs

Char (13) enter key

Replace the newline character with an empty character (that is, delete the newline character), you can write

Replace (field name, char (10),'')

Example: replace newline characters in characters with empty characters

SELECT *, REPLACE (detail, CHAR (10),'') AS displays the replaced content

Attached is the ASCII code table:

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

REPLACE (str,old_string,new_string)

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

It is very important that in the REPLACE function, the first argument is the column name without quotation marks ("). If you enclose quotation marks, such as a field name like" field_name ", the query will update the contents of the column to" field_name ", resulting in unexpected data loss.

The REPLACE function does not support regular expressions, so if you need to replace the text string with a pattern from the external library that requires MySQL user-defined functions (UDF).

These are all the contents of the article "how to change line characters for mysql". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Tags: Newline characters functions characters strings content knowledge articles fields tabs parameters carriage returns quotation marks horizontal empty characters syntax tabulation updates different big important Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux NVidia Docker Shulou Technology Redmi