CONCAT():
CONCAT() is used to concatenate two or more strings together.Example:
sqlCopy code
SELECT CONCAT('Hello', ' ', 'World') AS concatenated_string;
Output: Hello World
SUBSTRING():
SUBSTRING() is used to extract a portion of a string based on a starting position and length.Example:
sqlCopy code
SELECT SUBSTRING('MySQL Tutorial', 1, 5) AS substring_result;
Output: MySQL
UPPER() and LOWER():
UPPER() converts a string to uppercase, while LOWER() converts it to lowercase.Example:
sqlCopy code
SELECT UPPER('hello') AS upper_case, LOWER('WORLD') AS lower_case;
Output: HELLO, world
LENGTH():
LENGTH() returns the length (number of characters) of a string.Example:
sqlCopy code
SELECT LENGTH('MySQL') AS string_length;
Output: 5
TRIM():
TRIM() removes leading and trailing spaces from a string.Example:
sqlCopy code
SELECT TRIM(' Hello ') AS trimmed_string;
Output: Hello
REPLACE():
REPLACE() replaces occurrences of a substring within a string with another substring.Example:
sqlCopy code
SELECT REPLACE('Hello, World!', 'World', 'John') AS replaced_string;
Output: Hello, John!
LEFT() and RIGHT():
LEFT() returns a specified number of characters from the left of a string, while RIGHT() does the same from the right.Example:
sqlCopy code
SELECT LEFT('MySQL Tutorial', 5) AS left_string, RIGHT('MySQL Tutorial', 7) AS right_string;
Output: MySQL, Tutorial
LOCATE():
LOCATE() finds the position of a substring within a string.Example:
sqlCopy code
SELECT LOCATE('world', 'Hello, world!') AS position;
Output: 7
CONCAT_WS():
CONCAT_WS() concatenates strings with a specified separator.Example:
sqlCopy code
SELECT CONCAT_WS(', ', 'John', 'Doe') AS full_name;
Output: John, Doe
CHAR_LENGTH():
CHAR_LENGTH() returns the number of characters in a string, considering multi-byte characters.Example:
sqlCopy code
SELECT CHAR_LENGTH('Café') AS string_length;
Output: 4
These are some of the commonly used string functions in MySQL, and they can be helpful for various string manipulation tasks in your SQL queries.