

SELECT TRIM( FROM Code language: SQL (Structured Query Language) ( sql ) trim

The following statement removes both leading and trailing of the string. SELECT TRIM( LEADING '0' FROM '00001900') Code language: SQL (Structured Query Language) ( sql ) trim The following statement removes leading zero of a string because the trim_character is ‘0’. Of course, the length of the result string must be three. The following statement removes both leading and trailing spaces of the string. SELECT LENGTH( TRIM(TRAILING FROM ' SQL ')) The length of the string must be five because the TRIM function removes one space at the end of the string. The following statement uses the TRIM function with the TRAILING option removes all trailing blank spaces of the string. SELECT LENGTH( TRIM( LEADING FROM ' SQL ')) The length of the result string must be four because the TRIM function removes two spaces at the beginning of the string. You can test it by using the LENGTH function. The following statement uses the TRIM function with the LEADING option to remove all leading spaces of the string. (1 row) Code language: SQL (Structured Query Language) ( sql ) SELECT LENGTH( ' SQL ') Code language: SQL (Structured Query Language) ( sql ) length Suppose we have a string that contains two spaces at the beginning and one space at the end of the string ( ' SQL '). The TRIM function returns NULL if either trim_character or source string is NULL. If you specify BOTH or none of three, the TRIM function will remove both leading and trailing characters that match the trim_characters.If you specify TRAILING, the TRIM function will remove any trailing characters that match the trim_character.If you specify LEADING, the TRIM function will remove any leading characters that match the trim_character.Third, the LEADING, TRAILING, and BOTH specify the side of the source_string that the TRIM function will remove the trim_character. Second, place the source_string followed the FROM clause. If you do not specify trim_character the TRIM function will remove the blank spaces from the source string. TRIM( trim_character FROM source_string) Code language: SQL (Structured Query Language) ( sql )įirst, specify the trim_character, which is the character that the TRIM function will remove. The following shows the syntax of the TRIM function.

The TRIM function allows you to trim leading and/or trailing characters from a string. Summary: in this tutorial, we will introduce you to the SQL TRIM function that removes both leading and trailing characters from a string.
