

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Remove new line characters from rows in MySQL?
The Trim() function is used to remove new line characters from data rows in MySQL. Let us see 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) - > ); Query OK, 0 rows affected (0.57 sec)
Let us now 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\n '); Query OK, 1 row affected (0.18 sec) mysql> insert into tblDemotrail values(5,' \nTim '); Query OK, 1 row affected (0.12 sec)
Let us display all the records.
mysql> select *from tblDemotrail;
The following is the output that doesn’t look like normal record, since we included newline characters while adding records.
+------+------------------+ | id | name | +------+------------------+ | 1 |John | | 2 | Carol | | 3 | Sam | | 4 | Tom | | 5 |Tim | +------+------------------+ 5 rows in set (0.00 sec)
To remove new line characters, you need to use the following query.
mysql> update tblDemotrail SET name = TRIM(TRAILING '\n' FROM name); Query OK, 0 rows affected (0.00 sec) Rows matched: 5 Changed: 0 Warnings: 0
- Related Questions & Answers
- MySQL query to remove special characters from column values?
- How to remove special characters from a database field in MySQL?
- Remove new lines from string in PHP
- Search text containing a new line in MySQL?
- How to remove all non-alphanumeric characters from a string in MySQL?
- JavaScript Remove non-duplicate characters from string
- JavaScript - Remove first n characters from string
- C# Program to remove duplicate characters from String
- How to remove non-ASCII characters from strings
- How to Remove Characters from a String in Arduino?
- Remove first two characters of all fields in MySQL?
- Remove seconds from MySQL Datetime?
- PHP program to remove non-alphanumeric characters from string
- Remove all characters of first string from second JavaScript
- How to remove specific characters from a string in Python?
Advertisements