ORA-01830 when converting number to words

前端 未结 2 1552
无人共我
无人共我 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: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
    

提交回复
热议问题