2016-07-15 7 views
0

숫자 값을 단어로 변환하려고합니다. 다음 SQL을 사용하여 1069000. : 내가 좋아하는 일곱 개 숫자 값까지 성공적으로 수행숫자 값을 단어로 변환하는 중 오류가 발생했습니다 - Oracle

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

을하지만, 내가 좋아하는 또 하나의 제로 증가 할 때

날짜 형식 : 10,690,000 그것을 나에게 다음과 같은 오류를 제공합니다 그림은 전체 입력 문자열을 변환하기 전에 종료

사람의 도움을 10690000

같은 여덟 개 이상의 문자를 가진 단어로 숫자 값을 변환하십시오

미리 감사드립니다.

+0

,이 같은 "단지 10 개 5 백만 수천 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는 이미 그것을 작성했습니다.

내가되어 사용할 수 없습니다 것 때문에 사이트에 여기에 코드를 복제하거나 링크가 삭제 될 수

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; 
/
관련 문제