MySQL String Functions

This post will explain basic and important String Manipulation Function for MySQL.

Below is list of String functions with an example using MySQL Console.

CONCAT (Str1,Str2…):This function is used to concat two or more string and integer by passing string or integer arguments. If you try to concat NULL with string, then result will be NULL. You can also concat multiple argument using single function.

LEFT (str,len): This will return left most character from string and if you pass NULL argument then return NULL result.
RIGHT (str,len) : This will return right most character from string and if you pass NULL argument then return NULL result.
INSTR (str,substr) : This function is used to find starting position of given substring.
LOCATE (substr,str) : This function work same as INSTR(str,substr)
POSITION (substr IN str) : This function work same as INSTR(str,substr)
INSERT(str,pos,len,newstr) : This function is used to overwrite new string part on old string part. You require to pass position and length to replace old part of string using new part of string.
LENGTH(str): This function is used to find length of given string.
UPPER(str) / LOWER(str) : This both function is used to change string from lower to upper or upper to lowar case.

REPEAT (str,count): This function is used to repeat string by given count.

REPLACE(str,from_str,to_str): This function is used to replace a substring by new string. You can replace any part of your string by giving from_string and to_string.

REVERSE(str) : This function is used to reverse each word of string.

STRCMP(str1,str2): This function is used to compare two string. This is not case sensitive. If both string is match then it return 0 else it return 1 or -1 base on how first string is bigger than second string.

SUBSTRING (str,pos) : This function is used to return sub part of string by giving position.

SUBSTRING (str,pos,len): This function is used to return sub part of string by giving position and length of return string.

TRIM (str): This function is used to remove all prefixes or suffixes from string. You can also use LTRIM(str) and RTRIM(str) to remove space from left or right only.

Above all are basic and important String manipulation function in MySQL.


Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

If you like this post, then please share it with others.
Please follow dbrnd.com, I will share my experience towards the success of Database Research and Development Activity.

I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.

More from dbrnd.com

Leave a Reply

1 Comment on "MySQL String Functions"

Notify of
avatar
Sort by:   newest | oldest | most voted
Alexandr Omelchenko
Guest

Thanks! Here I have found all basic and important String Manipulation Function for MySql.
By the way, we have created a cheat sheet – “MySQL String Functions” with the whole list of MySql String Functions. You can find it here:
http://mysqlbackupftp.com/freebies/MySQL_Cheat_Sheet_String_Functions.pdf

wpDiscuz