如何以字和小数显示数字值

时间:2019-05-06 16:37:21

标签: sql oracle plsql

如何在oracle中用单词显示整数值

这是我尝试的SQL查询。 select to_char( to_date(5373484,'J'),'Jsp') from dual;

如果它是整数,则上述查询似乎无济于事 我想将整数(即515.24转换为oracle中的以下单词。 Five hundred and fifteen and 24 cents

1 个答案:

答案 0 :(得分:2)

一个简单的示例,它检查是否有任何小数。如果是这样,它们将分别拼写。

SQL> with test (col) as
  2    (select 4432 from dual union all
  3     select 515.24 from dual
  4    ),
  5  inter as
  6    (select col,
  7            regexp_substr(col, '^\d+') fir,
  8            case when col <> round(col) then regexp_substr(col, '\d+$') end sec
  9     from test
 10    )
 11  select col,
 12    to_char(to_date(fir, 'J'), 'JSP') ||
 13    case when sec is not null then ' and ' || to_char(to_date(sec, 'J'), 'JSP') ||' cents' end spell
 14  from inter;

       COL SPELL
---------- --------------------------------------------------
      4432 FOUR THOUSAND FOUR HUNDRED THIRTY-TWO
    515,24 FIVE HUNDRED FIFTEEN and TWENTY-FOUR cents

SQL>