ORA-01830 when converting number to words

前端 未结 2 1540
无人共我
无人共我 2021-01-27 11:51

High value is in decimal format eg.- 100.10, I want to convert it into word so I write below script but not getting execution by this..

SELECT SYMBO         


        
相关标签:
2条回答
  • 2021-01-27 12:27

    The error is raised since the value of high that you have shown is a decimal, that cannot be cast as an integer implicitly, unlike 100.00. So, it cannot be converted to Julian date.

    SELECT  UPPER(TO_CHAR(TO_DATE(100.10,'J'),'JSP'))AMT_IN_WORDS FROM DUAL;
    

    This causes

    ORA-01830: date format picture ends before converting entire input string

    This can be resolved by rounding the decimal to the nearest integer.

    SELECT  UPPER(TO_CHAR(TO_DATE(ROUND(100.10),'J'),'JSP'))AMT_IN_WORDS FROM DUAL;
    
    | AMT_IN_WORDS |
    |--------------|
    |  ONE HUNDRED |
    

    Demo

    If you really want the float component as well, although limited, you may refer this answer's EDIT2: How to convert number to words - ORACLE

    0 讨论(0)
  • 2021-01-27 12:36

    You can creation a function.

    CREATE OR REPLACE FUNCTION big_amt_in_words (p_input VARCHAR2) RETURN VARCHAR2
    IS
       v_running_input NUMBER;
       v_num NUMBER;
       v_amt_in_words VARCHAR2(2000);
    BEGIN
       v_running_input := P_input;
       FOR i IN (
                 SELECT RPAD(1, (rownum*3)+1, 0) num_value,
                        CASE LENGTH(RPAD(1, (rownum*3)+1, 0))
                            WHEN 4 THEN 'THOUSAND'
                            WHEN 7 THEN 'MILLION'
                            WHEN 10 THEN 'BILLION'
                            WHEN 13 THEN 'TRILLION'
                            WHEN 16 THEN 'QUADRILLION'
                            WHEN 19 THEN 'QUINTILLION'
                            WHEN 22 THEN 'SEXTILLION'
                            WHEN 25 THEN 'SEPTILLION'
                            WHEN 28 THEN 'OCTILLION'
                        END place_value
                  FROM DUAL
               CONNECT BY rownum < 10
                 ORDER BY rownum desc)
        LOOP
            v_num := TRUNC(v_running_input/i.num_value,0);
            IF v_num > 0 THEN
                v_amt_in_words := v_amt_in_words||' '||TO_CHAR(TO_DATE(v_num,'J'), 'JSP')||' '||i.place_value;
                v_running_input := v_running_input - (v_num * i.num_value);
            END IF;
        END LOOP;
        v_amt_in_words := v_amt_in_words||' '||TO_CHAR(TO_DATE(TRUNC(v_running_input),'J'), 'JSP')
                          ||' AND '||UPPER(TO_CHAR(TO_DATE((ROUND(v_running_input-TRUNC(v_running_input),2)*100),'J'),'JSP'))||' CENTS';
        RETURN TRIM(v_amt_in_words);
    END;
    /
    

    To use it,

    SELECT BIG_AMT_IN_WORDS(65763245345658.12) amt_in_words 
      FROM DUAL;
    
    Output
    ---------------------------------------------
    SIXTY-FIVE TRILLION SEVEN HUNDRED SIXTY-THREE BILLION TWO HUNDRED FORTY-FIVE MILLION THREE HUNDRED FORTY-FIVE THOUSAND SIX HUNDRED FIFTY-EIGHT AND TWELVE CENTS
    
    0 讨论(0)
提交回复
热议问题