有人能告诉oracle sql查询将10位数转换成单词吗? 例如我有像9876543210这样的数字,我会转换 这些数字为八十八,五,四,三个零。
答案 0 :(得分:2)
实际上,为此目的,你可以使用一堆replace()
s:
select replace(replace(. . . . replace(col, '0', 'ZERO '
), '1', 'ONE '
. . .
)
你需要10个,每个数字一个。你可能想在最后一个之后扔一个TRIM()
以删除最后一个空格。
答案 1 :(得分:1)
with num (n) as
(
select 9876543210
from dual
)
,dict (digit,descr) as
(
select substr(column_value,1,1) as digit
,substr(column_value,3) as description
from table
(
sys.ODCIVARCHAR2LIST
(
'0 ZERO','1 ONE','2 TWO','3 THREE','4 FOUR','5 FIVE','6 SIX','7 SEVEN','8 EIGHT','9 NINE'
)
) t
)
select listagg ((select d.descr from dict d where d.digit = n.digit),' ')
within group (order by i) as digits
from (select level as i
,substr(to_char(n),level,1) as digit
from num
connect by level <= length(to_char(n))
) n
+---------------------------------------------------+
| DIGITS |
+---------------------------------------------------+
| NINE EIGHT SEVEN SIX FIVE FOUR THREE TWO ONE ZERO |
+---------------------------------------------------+