如下数据串9358.0000~123.3478~9876.0123~。想要使返回的数据串为9358.00~123.35~9876.01该使用哪个函数进行截取?请高手赐教。

解决方案 »

  1.   

    select cast(123.5060 as dec(18,2)) from dual 自己先来一个。
      

  2.   

    select round(123.5060,2) from dual
    四舍五入
      

  3.   

    select trim(to_char(round(to_number(regexp_substr('9358.0000~123.3478~9876.0123~','[^~]+',1,1)),2),999999.99) )
    ||'~'|| trim(to_char(round(to_number(regexp_substr('9358.0000~123.3478~9876.0123~','[^~]+',1,2)),2),999999.99)) 
    ||'~'|| trim(to_char(round(to_number(regexp_substr('9358.0000~123.3478~9876.0123~','[^~]+',1,3)),2),999999.99))
    from dual
      

  4.   

    select trim(to_char(round(to_number(regexp_substr('9358.0000~123.3478~9876.0123~','[^~]+',1,1)),2),999999.99) )
    ||'~'|| trim(to_char(round(to_number(regexp_substr('9358.0000~123.3478~9876.0123~','[^~]+',1,2)),2),999999.99)) 
    ||'~'|| trim(to_char(round(to_number(regexp_substr('9358.0000~123.3478~9876.0123~','[^~]+',1,3)),2),999999.99))
    from dual
      

  5.   


    with t as(
    select '~9358.0000~123.3478~9876.0123~' str from dual
    )
    select
           replace(wm_concat(trim(to_char(round(substr(str,
                                instr(str, '~', 1, rownum) + 1,
                                instr(str, '~', 1, rownum + 1) -
                                instr(str, '~', 1, rownum) - 1),
                         2),
                   '99999999990.99'))),',','~')
      from t
    connect by rownum < length(str) - length(replace(str, '~', '')) - 1
    9358.00~123.35~9876.01