Oracle:将数字转换为除英语之外的其他语言的单词
发布时间:2020-12-12 13:16:09 所属栏目:百科 来源:网络整理
导读:我试图用文字转换数字. select to_char(to_date(:number,'j'),'jsp') from dual;SELECT TO_CHAR (TO_DATE (24834,'jsp') FROM DUAL;//Output: twenty-four thousand eight hundred thirty-four 但问题是我需要转换其他语言的数字而不是英语.也许你有任何想法
我试图用文字转换数字.
select to_char(to_date(:number,'j'),'jsp') from dual; SELECT TO_CHAR (TO_DATE (24834,'jsp') FROM DUAL; //Output: twenty-four thousand eight hundred thirty-four 但问题是我需要转换其他语言的数字而不是英语.也许你有任何想法如何做到这一点? 我需要转换成拉脱维亚语. 解决方法这是一个很酷的技巧(采用Julian和SPell的jsp格式).我发现 Ask Tom article提供了更多细节.但基本上jsp格式只适用于英语,但你可以将它包装在一个函数中并将英语翻译成另一种语言.例如,Tom的spell_number函数如下: create or replace function spell_number( p_number in number ) return varchar2 as type myArray is table of varchar2(255); l_str myArray := myArray( '',' thousand ',' million ',' billion ',' trillion ',' quadrillion ',' quintillion ',' sextillion ',' septillion ',' octillion ',' nonillion ',' decillion ',' undecillion ',' duodecillion ' ); l_num varchar2(50) default trunc( p_number ); l_return varchar2(4000); begin for i in 1 .. l_str.count loop exit when l_num is null; if ( substr(l_num,length(l_num)-2,3) <> 0 ) then l_return := to_char( to_date( substr(l_num,3),'J' ),'Jsp' ) || l_str(i) || l_return; end if; l_num := substr( l_num,1,length(l_num)-3 ); end loop; return l_return; end; / 法语(显然)的版本只使用spell_number和一些法语翻译: create or replace function spell_number_french( p_number in number ) return varchar2 as begin return replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( replace( lower( spell_number( p_number )),'duodecillion','bidecillion' ),'quintillion','cintillion' ),'billion','milliard' ),'thousand','mille' ),'hundred','cent' ),'ninety','quatre-vingt-dix'),'eighty','quatre-vingt' ),'seventy','soixante-dix' ),'sixty','soixante' ),'fifty','cinquante' ),'forty','quarante' ),'thirty','trente' ),'twenty','vingt' ),'nineteen','dix-neuf' ),'eighteen','dix-huit' ),'seventeen','dix-sept' ),'sixteen','seize' ),'fifteen','quinze' ),'fourteen','quatorze' ),'thirteen','treize' ),'twelve','douze' ),'eleven','onze' ),'ten','dix' ),'nine','neuf' ),'eight','huit' ),'seven','sept' ),'five','cinq' ),'four','quatre' ),'three','trois' ),'two','deux' ),'one','un' ),'dix-six','dix-cinq','dix-quatre','dix-trois','dix-deux','dix-un','-un ','-une ' ),'un cent','un mille','une','un' ); end spell_number_french; 做一些类似于您选择的语言的事情.请参阅Ask Tom链接以获得更详细的讨论. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |