Remove or Trim First or Last Few Characters in MySQL Database with SQL

Another useful string function in MySQL database is TRIM() which will return a text string after removing the matching leading or trailing characters, also known as prefixes or suffixes. It’s been described by MySQL reference as function that returns the string str with all remstr prefixes or suffixes removed. If none of the specifiers BOTH, LEADING, or TRAILING is given, BOTH is assumed. remstr is optional and, if not specified, spaces are removed.

Syntax of TRIM():

TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str), TRIM([remstr FROM] str)

For example:

SELECT TRIM(’ bar ‘);

will return ‘bar’ (spaces dropped).

SELECT TRIM(LEADING ‘x’ FROM ‘xxxbarxxx’);

will return ‘barxxx’ (only leading x characters is removed).

SELECT TRIM(BOTH ‘x’ FROM ‘xxxbarxxx’);

will return ‘bar’ (leading and trailing xs is dropped).

SELECT TRIM(TRAILING ‘xyz’ FROM ‘barxxyz’);

will return ‘barx’ (trailing xyz is cleared).

This function is multi-byte safe. And it can also be used with other SQL command such as UPDATE to perform modification update directly on database table data with SQL statements using tool such as phpMyAdmin.

Share and contribute or get technical support and help at My Digital Life Forums.



Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting


Custom Search

New Articles

Incoming Search Terms for the Article

mysql trim - SQL remove characters - sql remove last character - trim command in sql - mysql trim update - trim SQL command - TRIM Mysql - sql remove character - SQL remove first character - remove characters sql - mysql trim text - mysql select trim - sql trim characters - mysql remove last character - access query trim all but last character - sql remove leading characters - remove characters in SQL - sql trim char - sql command trim - sql trim last character - sql first character - trim characters - sql trim update - sql trim - trim characters sql - remove first character sql - trim sql - sql remove char - SQL remove last characters - mysql trim trailing - remove character in SQL - sql delete last character - sql strip last character - php remove characters - remove characters from string SQL - SQL Remove leading character - mysql replace character - sql remove first characters - sql replace last character - remove last char in sql - remove string sql - sql remove last char - trim first two characters in access - sql select first characters - sql query trim - mysql trim - all - sql delete character - remove first character from string - sql update remove characters -