Oracle
 sql >> Baza danych >  >> RDS >> Oracle

Konwertuj liczbę na słowa w indyjskim systemie liczbowym

Skrzypce SQL

Konfiguracja schematu 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;

Zapytanie 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

Wyniki :

|        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. Pobierz anonimowy wynik bloku PLSQL

  2. Wprowadzenie do instrukcji FORALL w bazie danych Oracle

  3. Optymalizator w Oracle Database 19c

  4. Wykonywanie dynamicznego DDL w procedurze PL/SQL poprzez uprawnienia roli definiującego

  5. Oracle i programowanie