Oracle
 sql >> Teknologi Basis Data >  >> RDS >> Oracle

ORA-01830 saat mengonversi angka menjadi kata

Anda dapat membuat fungsi.

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;
/

Untuk menggunakannya,

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


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Contoh database Oracle SQL

  2. TO_DATE saya sepertinya tidak berfungsi dengan baik

  3. Menyetel Kueri SQL di Oracle

  4. Java - Bagaimana cara memanggil prosedur Oracle dengan tipe khusus?

  5. Cara mengetahui nomor baris, nama prosedur di PL/SQL jika terjadi kesalahan