The Oracle/PLSQL TRIM function removes all specified characters either from the beginning or the end of a string.
The syntax for the TRIM function in Oracle/PLSQL is:
TRIM( [ [ LEADING | TRAILING | BOTH ] trim_character FROM ] string1 )
- 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
- The character that will be removed from string1. If this parameter is omitted, the TRIM function will remove space characters from string1.
- string1
- The string to trim.
The TRIM function returns a string value.
Note
- If you do not choose a value for the first parameter (LEADING, TRAILING, BOTH), the TRIM function will remove trim_character from both the front and end of string1.
select (' PAKISTAN ') from dual
PAKISTAN
select trim(' PAKISTAN ') from dual
PAKISTAN
select length((' PAKISTAN ')) from dual
30
select length(trim(' PAKISTAN ')) from dual
8
select length('PAKISTAN ') from dual
25
select length(trim('PAKISTAN ')) from dual
8
select TRIM(' ' FROM ' tech ') from dual
tech
-----------------------------------------------------------------------------------------------------------------
2300000
select TRIM(LEADING '0' FROM '000012300000')from dual
12300000
------------------------------------------------------------------------------------------------------------------
select TRIM(TRAILING '2' FROM 'Tech12') from dual
Tech1
select TRIM(TRAILING '1' FROM 'Tech1') from dual
Tech
--------------------------------------------------------------------------------------------------------------------
select TRIM(BOTH '1' FROM '123Tech111') from dual
23Tech
No comments:
Post a Comment