Example
Remove leading and trailing spaces from a string:
SELECT TRIM(' SQL Tutorial ') AS TrimmedString;
Definition and Usage
The TRIM() function removes leading and trailing spaces from a string. Continue reading MySQL TRIM Function
Remove leading and trailing spaces from a string:
SELECT TRIM(' SQL Tutorial ') AS TrimmedString;
The TRIM() function removes leading and trailing spaces from a string. Continue reading MySQL TRIM Function
Return a substring of a string before a specified number of delimiter occurs:
SELECT SUBSTRING_INDEX("www.iampsp.com", ".", 1);
The SUBSTRING_INDEX() function returns a substring of a string before a specified number of delimiter occurs. Continue reading MySQL SUBSTRING_INDEX Function
Extract a substring from a string (start at position 1, extract 3 characters):
SELECT SUBSTRING("SQL Tutorial", 1, 3) AS ExtractString;
The SUBSTRING() function extracts a substring from a string (starting at any position). Continue reading MySQL SUBSTRING Function
Extract a substring from a string (start at position 5, extract 3 characters):
SELECT SUBSTR("SQL Tutorial", 5, 3) AS ExtractString;
The SUBSTR() function extracts a substring from a string (starting at any position). Continue reading MySQL SUBSTR Function
Compare two strings:
SELECT STRCMP("SQL Tutorial", "SQL Tutorial");
The STRCMP() function compares two strings. Continue reading MySQL STRCMP Function
Return a string with 10 space characters:
SELECT SPACE(10);
The SPACE() function returns a string of the specified number of space characters. Continue reading MySQL SPACE Function
Remove trailing spaces from a string:
SELECT RTRIM("SQL Tutorial ") AS RightTrimmedString;
The RTRIM() function removes trailing spaces from a string. Continue reading MySQL RTRIM Function
Right-pad the string with “ABC”, to a total length of 20:
SELECT RPAD("SQL Tutorial", 20, "ABC");
The RPAD() function right-pads a string with another string, to a certain length.
Note: Also look at the LPAD() function. Continue reading MySQL RPAD Function
Extract 4 characters from a string (starting from right):
SELECT RIGHT("SQL Tutorial is cool", 4) AS ExtractString;
The RIGHT() function extracts a number of characters from a string (starting from right).
Tip: Also look at the LEFT() function. Continue reading MySQL RIGHT Function
Reverse a string:
SELECT REVERSE("SQL Tutorial");
The REVERSE() function reverses a string and returns the result. Continue reading MySQL REVERSE Function