Monday, May 7, 2018

Using TRIM in PLSQL Query

https://plsqlquery.blogspot.com/2018/05/using-trim-in-plsql-query.html

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.
Returns
The TRIM function returns a string value.
Note
  • If you do not choose a value for the first parameter (LEADINGTRAILINGBOTH), 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

-----------------------------------------------------------------------------------------------------------------

LEADING

select TRIM(LEADING '1' FROM '12300000')from dual
2300000


select TRIM(LEADING '0' FROM '000012300000')from dual
12300000

------------------------------------------------------------------------------------------------------------------

TRAILING

select TRIM(TRAILING '2' FROM 'Tech12') from dual
Tech1


select TRIM(TRAILING '1' FROM 'Tech1') from dual
Tech

--------------------------------------------------------------------------------------------------------------------

BOTH

select TRIM(BOTH '1' FROM '123Tech111') from dual
23Tech

No comments:

Post a Comment

XLA to GL Link

  https://plsqlquery.blogspot.com/2025/12/xla-to-gl-link.html SELECT             acr.cash_receipt_id,             acr.receipt_number,       ...