LTRIM
LTRIM is a function in SQL that removes any leading white spaces from a string.
LTRIM(string)
- string: This parameter refers to the source string from which the leading spaces need to be removed by the LTRIM() function in MySQL.
Example
Output
Explanation
The LTRIM function removes the leading spaces from the string ’ SQL Documentation’. The remaining string ‘SQL Documentation’ is then returned.
LTRIM(text, characters)
- text: This is a required parameter for the LTRIM function. It refers to the specific string in which the function applies the operation. Any leading characters that match the specified characters parameter are removed from this text string.
- characters: This optional parameter indicates the characters to be removed from the beginning of the text string. If this parameter is not provided, the LTRIM function will by default remove spaces.
Example
Output
Explanation
The LTRIM()
function is used in PostgreSQL to remove the longest string containing only spaces from the start of the string. In the provided example, ’ HelloWorld’ has resulted in ‘HelloWorld’ after applying the LTRIM()
function.
LTRIM(string)
- string: This refers to the actual string in which the unnecessary leading spaces need to be removed. LTRIM removes all the leading spaces in the string provided as the parameter.
Example
Output
Explanation
In the given example, the LTRIM
function is used to remove the leading spaces from the string ’ SQL Server’. The resulting output is ‘SQL Server’ without any leading spaces.
LTRIM(string, trim_character)
- string: This parameter represents the input string from which the leading characters need to be trimmed.
- trim_character: This parameter refers to the specific characters to be trimmed from the beginning of the input string. In case this parameter is not provided, the function by default trims leading whitespace characters.
Example
Output
Explanation
The LTRIM
function removes all the specified leading characters from a string. In the presented example, it removes leading spaces from the string ’ Hello World’. The resulting output is ‘Hello World’, with no leading spaces.
LTRIM(string, chars)
- string: This is the main string from which leading characters specified in the ‘chars’ parameter will be removed if present.
- chars: These are the specific characters to be removed from the beginning of the string. If no character set is specified, default behavior is to remove whitespace.
Example
Output
Explanation
The LTRIM()
function in SQLite removes all spaces on the left side of a string. In the given example, it removes all spaces on the left of ’ HelloWorld’, resulting in ‘HelloWorld’.