-- select sp_encriptacion('jose', 'E');
-- select sp_encriptacion('ª¯³¥', 'D');
create or replace function sp_encriptacion(texto character varying, accion char)
returns character varying as $$
declare
longitud integer;
i integer;
frase character varying;
frase_temp character varying;
begin
i = 1;
longitud = 0;
frase = '';
frase_temp = '';
longitud = length(texto);
while i <= longitud loop
if (accion = 'E') then
frase_temp = chr(ascii(substring(texto, i, 1)) + 64);
else
if (accion = 'D') then
frase_temp = chr(ascii(substring(texto, i, 1)) - 64);
end if;
end if;
frase = frase || frase_temp;
i = i + 1;
end loop;
return frase;
end;
$$ language plpgsql;
No hay comentarios:
Publicar un comentario