Home > Database > Mysql Tutorial > body text

Remove newlines from rows in MySQL?

WBOY
Release: 2023-09-04 22:21:07
forward
744 people have browsed it

从 MySQL 的行中删除换行符?

The Trim() function is used to remove newlines from data rows in MySQL. Let's look at an example. First, we will create a table. CREATE command is used to create a table.

mysql> create table tblDemotrail
- > (
- > id int,
- > name varchar(100)
- > );
Query OK, 0 rows affected (0.57 sec)
Copy after login

Now let’s insert some records.

mysql> insert into tblDemotrail values(1,'John ');
Query OK, 1 row affected (0.15 sec)

mysql> insert into tblDemotrail values(2,' Carol');
Query OK, 1 row affected (0.32 sec)

mysql> insert into tblDemotrail values(3,' Sam ');
Query OK, 1 row affected (0.17 sec)

mysql> insert into tblDemotrail values(4,' Tom ');
Query OK, 1 row affected (0.18 sec)

mysql> insert into tblDemotrail values(5,' Tim ');
Query OK, 1 row affected (0.12 sec)
Copy after login

Let's show all records.

mysql> select *from tblDemotrail;
Copy after login

The following output does not look like a normal record because we included newlines when adding the record.

+------+------------------+
| id   | name             |
+------+------------------+
| 1    |John              |
| 2    | Carol            |
| 3    | Sam              |
| 4    | Tom              |
| 5    |Tim               |
+------+------------------+
5 rows in set (0.00 sec)
Copy after login

To remove newlines you need to use the following query.

mysql> update tblDemotrail SET name = TRIM(TRAILING '' FROM name);
Query OK, 0 rows affected (0.00 sec)
Rows matched: 5 Changed: 0 Warnings: 0
Copy after login

The above is the detailed content of Remove newlines from rows in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!