
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
What is the purpose of MySQL TRIM() function?
MySQL TRIM() function is used to remove the specific suffix or prefix or both from the string. The working of TRIM() function can be understood with the help of its syntax −
Syntax
TRIM([{BOTH | LEADING | TRAILING} [str_to_remove] FROM] string)
Here,
- the argument BOTH means the prefixes from both left and right to be removed from the string.
- LEADING argument means that only leading prefixes to be removed.
- TRAILING argument means that only trailing prefixes to be removed.
- Str_to_remove is the argument which means the string we want to remove from the string.
- String argument means the string from which the prefixes have to be removed.
Example
mysql> Select TRIM(BOTH '0' FROM '0100'); +----------------------------+ | TRIM(BOTH '0' FROM '0100') | +----------------------------+ | 1 | +----------------------------+ 1 row in set (0.00 sec) mysql> Select TRIM(BOTH '**' from '**tutorialspoint.com**'); +------------------------------------------------+ | TRIM(BOTH '**' from '**tutorialspoint.com**') | +------------------------------------------------+ | tutorialspoint.com | +------------------------------------------------+ 1 row in set (0.00 sec) mysql> Select TRIM(Trailing '**' from '**tutorialspoint.com**'); +----------------------------------------------------+ | TRIM(Trailing '**' from '**tutorialspoint.com**') | +----------------------------------------------------+ | **tutorialspoint.com | +----------------------------------------------------+ 1 row in set (0.00 sec) mysql> Select TRIM(Leading '**' from '**tutorialspoint.com**'); +---------------------------------------------------+ | TRIM(Leading '**' from '**tutorialspoint.com**') | +---------------------------------------------------+ | tutorialspoint.com** | +---------------------------------------------------+ 1 row in set (0.00 sec)
- Related Articles
- What is the purpose of using MySQL CHAR_LENGTH() function? Which function is the synonym of it?
- In what cases, we cannot use MySQL TRIM() function?
- MySQL BIT_LENGTH() function is used for which purpose?
- What is the purpose of a function prototype in C/C++?
- What is the purpose of a self-executing function in JavaScript?
- What MySQL TRIM() function returns if 1st argument(i.e. BOTH, LEADING, TRAILING) is not specified?
- What is the purpose of ORDER BY columnname*1 in MySQL?
- What is the purpose of COALESCE function? Explain with the help of an example.
- trim() function in PHP
- What is the purpose of System Programs?
- What is the purpose of System Calls?
- What is the purpose of any research?
- What is the purpose of Human Life?
- What is the purpose of Risk Management?
- What is the Main Purpose of Blockchain?

Advertisements