English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
TheTrim()
The Trim() function is used to remove newline characters from data rows in MySQL. Let's look at an example. First, we will create a table. The CREATE command is used to create a table.
mysql> create table tblDemotrail - > ( - > id int( - > name varchar(100) - );
Now let's insert some records.
mysql> insert into tblDemotrail values (1'; mysql> insert into tblDemotrail values (2'; mysql> insert into tblDemotrail values (3'; mysql> insert into tblDemotrail values (4'; mysql> insert into tblDemotrail values (5';
Let's display all records.
mysql> select *from tblDemotrail;
The following output looks unusual because we included newline characters when adding records.
+------+------------------+ | id | name | +------+------------------+ | 1 |John | | 2 | Carol | | 3 | Sam | | 4 | Tom | | 5 |Tim | +------+------------------+ 5 rows in set (0.00 sec)
To remove newline characters, you need to use the following query.
mysql> update tblDemotrail SET name = TRIM(TRAILING '\n' FROM name); Rows matched: 5 Changed: 0 Warnings: 0