Skip to content Skip to sidebar Skip to footer

How To Format A Number Column In Oracle?

I try to spool output in a nice way, so i am formatting all VARCHAR2 columns to a5. However, my problematic columns are: SLOTNUM of type NUMBER(2) and FEEADJUSTMENT of type NUMBER(

Solution 1:

Because it's using the length of the column header, as the documentation says:

A NUMBER column's width equals the width of the heading or the width of the FORMAT plus one space for the sign, whichever is greater.

You can alias the column with a shorter name:

select slotnum as slotn, ...

You could also treat it as a string, but you'd still need an alias really:

selectto_char(slotnum, 'FM9999') as slotn, ...

You could alias is as slotnum, if you preferred, and the use format a5, but I think that would be less clear.

I'm not sure I'd describe forcing everything to a5 as 'nice', particularly as you have values lomger than that which ware forcing column wrapping. A matter of taste, I suppose...

Solution 2:

Format with this:

column SLOTNUM format a3;
column FEEADJUSTMENT format a5;

Post a Comment for "How To Format A Number Column In Oracle?"