locked
format 2 decimal in Oracle. RRS feed

  • Question

  • User-1075092149 posted

    i would like to ask how can i convert to 2 decimal from varchar2(100) text table column.

    i just use the following sql but can't ouput my expected output.

    select to_char(nvl(col1,0),'9999.99') from tableA;

     

    it return .00 if the column is empty. how can i output 0.00?

    also, i save as 1,2,,3 in another column. how can i convert to month by using 1,2,3...

    covert 1 to JAN

    convert 2 to FEB, etc.

    Wednesday, September 26, 2012 12:22 AM

Answers

  • User269602965 posted

    select to_char(nvl(col1,0),'9990.99') from tableA;

    change your number mask as above and zero comes back as 0.00

    SQL> select to_char(0,'9990.99') as test from dual;
    
    TEST
    --------
        0.00

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 26, 2012 6:40 PM