with
Numero as (
select 152 N from dual
union all select 14587 from dual
union all select 14 from dual
union all select 7816 from dual
union all select 174 from dual
union all select 458 from dual
union all select 17548987 from dual
union all select 458157 from dual
union all select 14850 from dual
union all select 21410 from dual
union all select 100 from dual
union all select 457500 from dual
union all select 82100 from dual
)
,
PreProcesado1 as (
select N
, floor(mod(N, 1000000) / 100000) MillarCentenas
, floor(mod(N, 100000) / 10000) MillarDecenas
, floor(mod(N, 10000) / 1000) MillarUnidades
, floor(mod(N, 1000) / 100) Centenas
, floor(mod(N, 100) / 10) Decenas
, floor(mod(N, 10)) Unidades
from Numero
)
select N
, case Centenas
when 0 then ''
when 1 then case when Decenas = 0 and Unidades = 0 then 'cien ' else 'ciento ' end
when 2 then 'doscientos '
when 3 then 'trescientos '
when 4 then 'cuatrocientos '
when 5 then 'quinientos '
when 6 then 'seiscientos '
when 7 then 'setecientos '
when 8 then 'ochocientos '
when 9 then 'novecientos '
end
|| case Decenas
when 0 then ''
when 2 then 'veinte '
when 3 then 'treinta '
when 4 then 'cuarenta '
when 5 then 'cincuenta '
when 6 then 'sesenta '
when 7 then 'setenta '
when 8 then 'ochenta '
when 9 then 'noventa '
when 1 then
case Unidades
when 0 then 'diez '
when 1 then 'once '
when 2 then 'doce '
when 3 then 'trece '
when 4 then 'catorce '
when 5 then 'quince '
else 'dieci'
end
end
|| case when Decenas > 1 and Unidades <> 0 then 'y ' else '' end
|| case
when Decenas = 1 and Unidades < 6 then ''
else
case Unidades
when 0 then ''
when 1 then 'uno'
when 2 then 'dos'
when 3 then 'tres'
when 4 then 'cuatro'
when 5 then 'cinco'
when 6 then 'seis'
when 7 then 'siete'
when 8 then 'ocho'
when 9 then 'nueve'
end
end
NumeroEnLetras
from PreProcesado1