2016-07-15 13 views
0

数値を単語に変換しようとしています。次のSQL使って1069000.::私のような7つの数値まで正常に行わ数値を単語に変換するエラー - Oracle

**UPPER(TO_CHAR (TO_DATE ((1069000), 'j'), 'jsp'))in_words** 

をしかしように私は、ゼロ1以上を増やすとき:

日付フォーマット:それは私に次のエラーを与える1069万絵は、入力文字列全体を変換する前に終了し

誰の助けは1069万

のように8文字以上を持つ単語に数値を変換するためにしてください

ありがとうございます。

+0

、このような "ONLY TEN MILLION FIVE何千SIX何百もの"、ありがとう。 –

答えて

0
I have got the solution, Thanks to all. Please view the solution below. 



SELECT upper(case 
        when length(floor(instr_amount)) > 12 then 
        TO_CHAR(TO_DATE(floor(floor(instr_amount)/1000000000000), 'j'), 
          'jsp') || ' TRILLION ' || 
        DECODE(substr(floor(instr_amount), length(floor(instr_amount)) - 11, 3), 
          0, 
          '', 
          (TO_CHAR(TO_DATE(to_number(substr(floor(instr_amount), 
                  length(floor(instr_amount)) - 11, 
                  3)), 
              'J'), 
            'JSP')) || ' BILLION ') || 
        DECODE(substr(floor(instr_amount), length(floor(instr_amount)) - 8, 3), 
          0, 
          '', 
          (TO_CHAR(TO_DATE(to_number(substr(floor(instr_amount), 
                  length(floor(instr_amount)) - 8, 
                  3)), 
              'J'), 
            'JSP')) || ' MILLION ') || 
        DECODE(substr(floor(instr_amount), length(floor(instr_amount)) - 5), 
          0, 
          '', 
          (TO_CHAR(TO_DATE(substr(floor(instr_amount), 
                length(floor(instr_amount)) - 5), 
              'J'), 
            'JSP'))) || 
        decode((instr_amount - floor(instr_amount)) * 100, 
          0, 
          '', 
          ' AND ' || 
          TO_CHAR(TO_DATE((instr_amount - floor(instr_amount)) * 100, 'j'), 
            'jsp') || ' CENTS') 
        when length(floor(instr_amount)) > 9 then 
        TO_CHAR(TO_DATE(floor(floor(instr_amount)/1000000000), 'j'), 'jsp') || 
        ' BILLION ' || 
        DECODE(substr(floor(instr_amount), length(floor(instr_amount)) - 8, 3), 
          0, 
          '', 
          (TO_CHAR(TO_DATE(to_number(substr(floor(instr_amount), 
                  length(floor(instr_amount)) - 8, 
                  3)), 
              'J'), 
            'JSP')) || ' MILLION ') || 
        DECODE(substr(floor(instr_amount), length(floor(instr_amount)) - 5), 
          0, 
          '', 
          (TO_CHAR(TO_DATE(substr(floor(instr_amount), 
                length(floor(instr_amount)) - 5), 
              'J'), 
            'JSP'))) || 
        decode((instr_amount - floor(instr_amount)) * 100, 
          0, 
          '', 
          ' AND ' || 
          TO_CHAR(TO_DATE((instr_amount - floor(instr_amount)) * 100, 'j'), 
            'jsp') || ' CENTS') 
        when length(floor(instr_amount)) > 7 then 
        TO_CHAR(TO_DATE(floor(floor(instr_amount)/1000000), 'j'), 'jsp') || 
        ' MILLION ' || 
        DECODE(substr(floor(instr_amount), length(floor(instr_amount)) - 5), 
          0, 
          '', 
          (TO_CHAR(TO_DATE(substr(floor(instr_amount), 
                length(floor(instr_amount)) - 5), 
              'J'), 
            'JSP'))) || 
        decode((instr_amount - floor(instr_amount)) * 100, 
          0, 
          '', 
          ' AND ' || 
          TO_CHAR(TO_DATE((instr_amount - floor(instr_amount)) * 100, 'j'), 
            'jsp') || ' CENTS') 
        else 
        decode((floor(instr_amount)), 
          0, 
          '', 
          ((TO_CHAR(TO_DATE((floor(instr_amount)), 'J'), 'JSP')))) || 
        decode((instr_amount - floor(instr_amount)) * 100, 
          0, 
          '', 
          ' AND ' || 
          TO_CHAR(TO_DATE((instr_amount - floor(instr_amount)) * 100, 'j'), 
            'jsp') || ' CENTS') 
       end) in_words FROM mytable 
0

あなたのアプローチにはいくつかの制限があります。スペル数が7文字以上の場合は、独自の関数を使用する必要があります。幸いなことに、Tom Kyteはすでにそれを書いています。

は、私がunavaliableだろう起因するサイトに、ここでのコードを複製したり、リンクが削除される

https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1407603857650参照:例えば

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, length(l_num)-2, 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; 
/
関連する問題