The LTRIM() function in MySQL is used to remove leading spaces (spaces at the beginning of a string) from a given string. It does not remove spaces in the middle or at the end of the string, only those that appear at the start.
Syntax:
LTRIM(str)
str: The string from which the leading spaces will be removed.
Example Usage:
-
Basic Example:
SELECT LTRIM(' Hello World') AS result;Result:
'Hello World'This query removes the leading spaces before "Hello World."
-
Using with a table:
SELECT LTRIM(name) AS trimmed_name FROM users;If the
namecolumn in theuserstable has leading spaces, this will remove them in the output.
Important Notes:
LTRIM()only removes the spaces at the beginning of the string. If you need to remove spaces from both the beginning and the end, use theTRIM()function instead.- It does not remove any non-space characters at the start of the string.
No comments:
Post a Comment