
- 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
How can I eradicate some specific suffix or prefix or both from a MySQL string?
MySQL TRIM() function is used to eradicate a 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 'AB' FROM 'ABCDAB'); +-------------------------------+ | TRIM(BOTH 'AB' FROM 'ABCDAB') | +-------------------------------+ | CD | +-------------------------------+ 1 row in set (0.00 sec) mysql> Select TRIM(Trailing 'AB' FROM 'ABCDAB'); +-----------------------------------+ | TRIM(Trailing 'AB' FROM 'ABCDAB') | +-----------------------------------+ | ABCD | +-----------------------------------+ 1 row in set (0.00 sec) mysql> Select TRIM(Leading 'AB' FROM 'ABCDAB'); +----------------------------------+ | TRIM(Leading 'AB' FROM 'ABCDAB') | +----------------------------------+ | CDAB | +----------------------------------+ 1 row in set (0.00 sec)
- Related Articles
- How can we eradicate leading and trailing space characters from a string in MySQL?
- How to Add Prefix or Suffix to a Range of Cells in Excel
- How to Add Prefix or Suffix into Cell Values in Google Sheets?
- How to check if string or a substring of string ends with suffix in Python?
- How can we remove all the prefixes or suffixes from a given string in MySQL?
- How can I install or enable innoDB in MySQL?
- Check if suffix and prefix of a string are palindromes in Python
- How can I update all elements in an array with a prefix string?
- How can I avoid too many OR statements in a MySQL query?
- How to remove double or more spaces from a string in MySQL?
- match_results prefix() and suffix() in C++
- How can I know whether MySQL Server is alive or not?
- How can I export values based on some conditions from MySQL table into a file?
- How can you test if some record exists or not in a MySQL table using Python?
- How can I remove the leading and trailing spaces both at once from a string by using MySQL LTRIM() and RTRIM() functions?

Advertisements