Home >Database >Mysql Tutorial >Remove newlines from rows in MySQL?

Remove newlines from rows in MySQL?

WBOY
WBOYforward
2023-09-04 22:21:07820browse

从 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)

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)

Let's show all records.

mysql> select *from tblDemotrail;

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)

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

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete