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

Ubah Angka menjadi Kata dalam Sistem Penomoran India

SQL Fiddle

Pengaturan Skema Oracle 11g R2 :

CREATE TABLE numbers ( value ) AS
SELECT               0 FROM DUAL UNION ALL
SELECT          123456 FROM DUAL UNION ALL
SELECT        12345678 FROM DUAL UNION ALL
SELECT   1234567890123 FROM DUAL UNION ALL
SELECT 123456789012345 FROM DUAL UNION ALL
SELECT 900000000000000 FROM DUAL UNION ALL
SELECT 700000001200000 FROM DUAL UNION ALL
SELECT 543000000000000 FROM DUAL;

Kueri 1 :

WITH rsqfc ( original, value, suffix, result, lvl, mxlvl ) AS (
  SELECT value,
         TRUNC( value / 10000000 ),
         CAST( 'CRORE ' AS VARCHAR2(4000) ),
         CAST(
           RTRIM(
             CASE
             WHEN MOD( TRUNC( value / 100000 ), 100 ) > 0
             THEN TO_CHAR(
                    TO_DATE(
                      MOD( TRUNC( value / 100000 ), 100 ),
                      'J'
                    ),
                    'JSP'
                  ) || ' LAKH '
             END
             ||
             CASE
             WHEN value = 0
             THEN 'ZERO'
             WHEN MOD( value, 100000 ) > 0
             THEN TO_CHAR(
                    TO_DATE(
                      MOD( value, 100000 ),
                      'J'
                    ),
                    'JSP'
                  ) || ' '
             END
           )
           AS VARCHAR2(4000)
         ),
         1,
         CEIL( LENGTH( ABS( value ) ) / 7 )
  FROM   numbers
UNION ALL
  SELECT original,
         TRUNC( value / 10000000 ),
         'CRORE ' || suffix,
         RTRIM(
           CASE
           WHEN MOD( TRUNC( value / 100000 ), 100 ) > 0
           THEN TO_CHAR(
                  TO_DATE(
                    MOD( TRUNC( value / 100000 ), 100 ),
                    'J'
                  ),
                  'JSP'
                ) || ' LAKH ' || suffix
           END
           ||
           CASE
           WHEN MOD( value, 100000 ) > 0
           THEN TO_CHAR(
                  TO_DATE(
                    MOD( value, 100000 ),
                    'J'
                  ),
                  'JSP'
                ) || ' ' || suffix
           END
           || result
         ),
         lvl + 1,
         mxlvl
  FROM   rsqfc
  WHERE  lvl < mxlvl
)
SELECT original, result
FROM   rsqfc
WHERE  lvl = mxlvl

Hasil :

|        ORIGINAL |                                                                                                                                           RESULT |
|-----------------|--------------------------------------------------------------------------------------------------------------------------------------------------|
|               0 |                                                                                                                                             ZERO |
|          123456 |                                                                                            ONE LAKH TWENTY-THREE THOUSAND FOUR HUNDRED FIFTY-SIX |
|        12345678 |                                                                        ONE CRORE TWENTY-THREE LAKH FORTY-FIVE THOUSAND SIX HUNDRED SEVENTY-EIGHT |
|   1234567890123 |                    ONE LAKH CRORE TWENTY-THREE THOUSAND FOUR HUNDRED FIFTY-SIX CRORE SEVENTY-EIGHT LAKH NINETY THOUSAND ONE HUNDRED TWENTY-THREE |
| 123456789012345 | ONE CRORE CRORE TWENTY-THREE LAKH CRORE FORTY-FIVE THOUSAND SIX HUNDRED SEVENTY-EIGHT CRORE NINETY LAKH TWELVE THOUSAND THREE HUNDRED FORTY-FIVE |
| 900000000000000 |                                                                                                                                 NINE CRORE CRORE |
| 700000001200000 |                                                                                                                    SEVEN CRORE CRORE TWELVE LAKH |
| 543000000000000 |                                                                                                          FIVE CRORE CRORE FORTY-THREE LAKH CRORE |



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Bagaimana cara terhubung ke database Oracle menggunakan VBScript dan UFT?

  2. Pembuatan Oracle Trigger dengan kesalahan kompilasi, ORA-02289:urutan tidak ada

  3. Tidak dapat terhubung ke Oracle DB mendapatkan kesalahan sebagai java.sql.SQLException:Pengecualian Io:Adaptor Jaringan tidak dapat membuat koneksi

  4. Koherensi:Kesalahan:Tidak dapat menemukan atau memuat kelas utama com.tangosol.net.DefaultCacheServer

  5. Bagaimana cara mengonversi tanggal ke stempel waktu (format DD-MON-YYYY HH24:MI:SS.FF) di oracle?