TRIM – Trim in oracle

By Santhosh N

This explains how to trim the character(s) specified on the either side of the string

Oracle has a function by the name, TRIM used to remove the specified character(s) both from the left hand side or right hand side or both sides of the string.

Syntax: TRIM([LEADING | TRAILING | BOTH [TrimChar]], str )

Here str is the original string and TrimChar is the character that needs to be removed from the left or right hand side or both the sides of the str. Optionally, one could specify leading or trailing or both to remove on left hand side, right hand side or both respectively.

Ex1: TRIM(‘   egg   ’)
This returns ‘egg’ as the result.

Ex2: TRIM(‘ ‘ from ‘      EggHead   ’)
This returns ‘EggHead’ as the result

Ex3: TRIM(LEADING ‘0’ FROM ‘0000EggHead’)
This returns ‘EggHead’ as the result

Ex4: TRIM(TRAILING ‘0’ FROM ‘EggHead0000’)
This returns ‘EggHead’ as the result

Ex5: TRIM(BOTH ‘0’ FROM ‘0000EggHead0000’)
This returns ‘EggHead’ as the result

Related FAQs

This explains how to trim the character(s) specified on the right hand side of the string
This explains how to trim the character(s) specified on the left hand side of the string
This explains how to replace the part(s) of the string with other string or char
This explains how to convert all the characters to the upper case alphabets
This explains how to convert all the characters to the lower case alphabets
This explains how to find the length of the string in oracle
TRIM – Trim in oracle  (3571 Views)