Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Autor : Joel Fernandez
- Fecha : 08/10/2015
- IDE : MySQL Workbench
- Web : www. codebotic.com
- Tema : FUnciones en MySQL
- */
- -- 4° convertir un numero decimal (maximo 2 cifras) a romanos
- delimiter *
- create function dec_a_romanos(n int)
- returns varchar(50)
- begin
- declare x int;
- declare y int;
- declare rom varchar(50);
- set rom='';
- set x=(n/10)-(n%10)/10; -- obtenemos la decena
- set y=n%10;-- obtenemos las unidades
- case(X)
- when '1' then set rom=concat(rom,'X');
- when '2' then set rom=concat(rom,'XX');
- when '3' then set rom=concat(rom,'XXX');
- when '4' then set rom=concat(rom,'XL');
- when '5' then set rom=concat(rom,'L');
- when '6' then set rom=concat(rom,'LX');
- when '7' then set rom=concat(rom,'LXX');
- when '8' then set rom=concat(rom,'LXXX');
- when '9' then set rom=concat(rom,'XC');
- end case;
- case(Y)
- when '1' then set rom=concat(rom,'I');
- when '2' then set rom=concat(rom,'II');
- when '3' then set rom=concat(rom,'III');
- when '4' then set rom=concat(rom,'IV');
- when '5' then set rom=concat(rom,'V');
- when '6' then set rom=concat(rom,'VI');
- when '7' then set rom=concat(rom,'VII');
- when '8' then set rom=concat(rom,'VIII');
- when '9' then set rom=concat(rom,'IX');
- end case;
- return rom;
- end
- *
- -- Ejemplo
- select dec_a_romanos(75);
Advertisement
Add Comment
Please, Sign In to add comment