Undesired leading blank space in oracle number format

I need to fill in numbers with leading zeros (only 8 digits) to display. I am using oracle.

select to_char(1011,'00000000') OPE_NO from dual; select length(to_char(1011,'00000000')) OPE_NO from dual; 

Instead of '00001011' I get '00001011'. Why am I getting extra spaces? What is the correct number formatting string to accomplish this?

PS I understand that I can just use trim() , but I want to better understand the formatting of numbers.

@Eddie: I already read the documentation. And yet I still do not understand how to get rid of leading gaps.

@David: Does this mean there is no way to use trim() ?

+15
sql oracle
Oct 01 '08 at 5:24
source share
2 answers

Use FM (fill mode), for example.

select to_char(1011,'FM00000000') OPE_NO from dual;

+29
01 Oct '08 at 8:11
source share

From the same documentation mentioned by EddieAwad :

Negative return values ​​automatically contain the first negative sign and positive values ​​automatically contain the leading space, if only the model format contains the MI, S or PR element format.




EDIT . The right way is to use the FM modifier, as Steve Bosman replied. Read more in the section Format Model Modifiers .

+6
01 Oct '08 at 5:40
source share



All Articles