Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you strip leading spaces in Oracle?

Tags:

sql

oracle

I need to strip leading spaces from a column in Oracle. I've Googled but haven't found any answers except to write my own function which I'd like to avoid.

What's the easiest way to accomplish this?

like image 313
larf311 Avatar asked Jul 13 '09 13:07

larf311


2 Answers

You can user LTRIM Oracle function:

SQL> select ltrim(' hello world') from dual;

LTRIM('HELLOWORLD')
-------------------
hello world

For ending spaces you can use RTRIM. And for more options check out TRIM.

like image 187
FerranB Avatar answered Nov 01 '22 09:11

FerranB


use the trim function removes all specified characters either from the beginning or the ending of a string.

trim( [ leading | trailing | both  [ trim_character ]  ]   string1 )
like image 42
joe Avatar answered Nov 01 '22 07:11

joe