Most used inbuild string function in MySQL
Character
- ASCII — This function returns the ASCII value of given character
SELECT ASCII(‘A’) — This gives the result of “65”
String
- CHAR_LENGTH() or CHARACTER_LENGTH() — Both function can be used and both returns the length of the string, “it counts space also as a value”.
SELECT CHAR_LENGTH(“Hello”);
SELECT CHARACTER_LENGTH(“Hello”); — Returns the value of “5”
2. CONCAT() — Used to merge multiple values into one string. Integer value also will get merged.
SELECT CONCAT(“Hello”, “ ”, “World”); — Returns “Hello World”
3. FORMAT(value, decimal limit) — Used to limit the decimal value from the given number. For ex:- The value is “56.2354”, Use decimal limit to 2 and you get an output of “56.23”.
SELECT FORMAT(56.2354,2); Returns “56.23”
4. LCASE() or LOWER() — Both functions takes the string parameter and converts it into lower case.
SELECT LCASE(“HELLO”);
SELECT LOWER(“HELLO”); — Both returns “hello”
5. LENGTH() — Counts the number of character in the string
SELECT LENGTH(“MySql”); — Returns “5”
6. REPLACE(string, from-string, new-string) — Case sensitive replacement
SELECT REPLACE(“Hello World”, “Hello”, “New”); — Returns “New World”
7. UCASE() or UPPER() — Both functions takes the string parameter and converts it into upper case.
SELECT UCASE(“hello”);
SELECT UPPER(“hello”); — Both returns “HELLO”