- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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
'); Query OK, 1 row affected (0.18 sec) mysql> insert into tblDemotrail values(5,'
Tim '); 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 '
' FROM name); Query OK, 0 rows affected (0.00 sec) Rows matched: 5 Changed: 0 Warnings: 0
- Related Articles
- MySQL query to remove special characters from column values?
- How to remove special characters from a database field in MySQL?
- How to remove all non-alphanumeric characters from a string in MySQL?
- Remove new lines from string in PHP
- Search text containing a new line in MySQL?
- Remove first two characters of all fields in MySQL?
- JavaScript Remove non-duplicate characters from string
- JavaScript - Remove first n characters from string
- How to Remove Characters from a String in Arduino?
- Remove specific fields/ rows and show other records in MySQL?
- C# Program to remove duplicate characters from String
- How to remove non-ASCII characters from strings
- Remove characters in a range from a Java StringBuffer Object
- How to remove certain characters from a string in C++?
- How to remove specific characters from a string in Python?

Advertisements