oracle中除数结果缺少0的问题

    技术2022-05-19  26

    select DECODE(TRUNC(round(decode(1, 0, 0, 1 / 1000 * 100), 1)),              0,              REPLACE(round(decode(1, 0, 0, 1 / 1000 * 100), 1),                      '.',                      '0.'),              TO_CHAR(round(decode(1, 0, 0, 1 / 1000 * 100), 1))) || '%' from dual

    第一:用TRUNC获取小数点前面的数值。

    第二:用decode函数做if或者else操作。

    第三:如果遇到只是小数点的则替换成“0.”。


    最新回复(0)