PL/SQL – TRIM function

TRIM Function
The TRIM function removes all the specified characters from the beginning or the end of the string.
SYNTAX
TRIM( [ [ LEADING | TRAILING | BOTH ] trim_character FROM ] string1 )
Parameters or Arguments
LEADING
The function will remove trim_character from the front of string1.
TRAILING
The function will remove trim_character from the end of string1.
BOTH

The function will remove trim_character from the front and end of string1.
trim_character

select TRIM ('super') from dual;
--
select TRIM (LEADING 0 from '008899000') from dual; -- removes the initial 0s from the string and gives 1223
--
select TRIM (LEADING 1 from '1123445111') from dual; -- remvoes the initial 1s and leaves the trailing 1s. Gives 23445111 as the answer.
--
select TRIM(' ' from '     orace   ') from dual; -- removes all the spaces from the string - gives oracle as answer
-- 
select TRIM (leading ' ' from '    oracle  ') from dual; -- removes the initial spaces from the string - gives oracle   (with trailing spaces still existing). 
-- 
select TRIM (trailing ' ' from '    oracle   ') from dual;   --removes trailing spaces from the string -- gives     oracle as answer
--no parameter
select TRIM (1 from '112233111') from dual;   -- since there is no parameter - 1 is taken from front and back - gives answer 2233
-- using BOTH
select TRIM (BOTH 'a' from 'a123bbcaaa') from dual; -- removes the initial 'a' as well as trailing 'aaa' from the string -- gives 123bbc as the answer.
--
select TRIM (BOTH 'bbc' from 'bbccnnabccbsbbc') from dual; -- this will give an error because the TRIM Set should have only one character - here we have 3 - bbc
--
select TRIM (BOTH 'b' from 'bbccnnabccbsbbc') from dual; -- gives ccnnabccbsbbc