Subscribe For Free Updates!

We'll not spam mate! We promise.

May 21, 2014

MySQL query to trim particular character from database column field

MySQL has some default functions to trim particular cahr or whitespaces from all the column field in database rows. MySQL provide four type of methods to trim char.
1. TRIM()
2. TRIM(LEADING)
3. TRIM(BOTH)
4. TRIM(TRAILING)

we can use above four methods in select, update and delete queries.
1. TRIM()
    TRIM() function is used to remove the whitespaces from start and end of the string.
Query : select TRIM( TechniqZone );
Result : TechniqZone

    This is trim the whitespaces in all the column.
Example : update table_name set field1=TRIM(field1)
2. TRIM(LEADING)
    TRIM(LEADING) function is used to remove the given charecter from the starting postion of the string.
Query : select TRIM(LEADING "'" FROM "TechniqZone'");
Rssult : TechniqZone

  
    This method is remove the single quotes(') from al the column starting postion.
Example : update table_name set field1=TRIM(LEADING "'" FROM field1)
3. TRIM(BOTH)
    TRIM(BOTH) function is used to remove particular charecter from both start and end postion of the string.
Query : select TRIM(BOTH '"' FROM '"TechniqZone"');
Rssult : TechniqZone

    This is used to remove the double quotes (") from both position.
Example : update table_name set field1=TRIM(BOTH "'" FROM field1)
4. TRIM(TRAILING)
    TRIM(TRAILING) function is used to remove given charecter from end of the string.
Query : select TRIM(TRAILING '.com' FROM "TechniqZone.com");
Rssult : TechniqZone

    This MySQL query remove the .com from the end of the string.
Example : update table_name set field1=TRIM(TRAILING "xxx" FROM field1)
Note : TRIM() and TRIM(BOTH) is same as when we remove whitesapces from database column.
MySQL query to trim particular charecter from database column field - TechniqZone

TechniqZone Socializer Widget
SOCIALIZE IT →
FOLLOW US →
SHARE IT →

0 comments:

Post a Comment