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 - trim sql - sql trim - trim command in sql - sql remove last character - sql remove string - Trim in sql - trim sql command - sql remove first character - php remove first char - sql command trim - sql remove character - sql first characters - all - trim mysql - trim in mysql - sql first character - sql trim last character - sql remove last char - sql strip - remove characters in sql - mysql select trim - sql remove first characters - characters.sql download - trim + sql - php delete first character - sql remove first char - mysql trim text - SQL replace last character - sql trim command - remove characters sql - sql strip string - perl remove first character - sql remove from string - sql trim characters - mysql trim leading - mysql remove from string - sql remove last characters - sql remove character from string - removing last character sql - sql trim last characters - mysql trim - sql replace first character - perl trim first character - remove first character php - SQL first 3 characters - mysql trim last character - sql delete character - remove first character sql -