1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| create or replace function COMPLETER_NUMERO_PAR_0(numero in VARCHAR2) return VARCHAR2 is
numeroComplete VARCHAR2(10);
longueur NUMBER;
position NUMBER;
isChiffre boolean;
nbChiffreOK NUMBER;
begin
numeroComplete := trim(numero);
longueur := length(trim(numero));
if (numeroComplete is not null and longueur > 0) then
position := 0;
isChiffre := true;
while position < longueur and isChiffre = true loop
position := position + 1;
if substr(numeroComplete, position, 1) not between '0' and '9' then
isChiffre := false;
end if;
end loop;
if isChiffre = false then
nbChiffreOK := position - 1;
else
nbChiffreOK := longueur;
end if;
while nbChiffreOK < 4 loop
numeroComplete := '0'||numeroComplete;
nbChiffreOK := nbChiffreOK + 1;
end loop;
else
numeroComplete := '0000';
end if;
return(numeroComplete);
end COMPLETER_NUMERO_PAR_0; |