I have a code that shows me the letters of a name and the number of letters in that name. But when he prints the letters and how many there are, he repeats the letters he has already read and tells me the spaces. Here the code:
create or REPLACE PROCEDURE nombre is
begin
declare
nombre VARCHAR(100) := 'Pepito perez';
letra VARCHAR(1);
letra2 VARCHAR(1);
contador int;
begin
for i in 1..LENGTH(nombre) loop
contador :=0;
letra := SUBSTR(nombre, i, 1);
for j in 1..LENGTH(nombre) loop
letra2 := SUBSTR(nombre, j, 1);
if (letra2 = letra) then
contador := contador +1;
end if;
end loop;
begin
dbms_output.put_line(letra||': '|| contador);
end;
end loop;
end;
end;
The result it throws is:
SQL> exec nombre
p: 3
e: 3
p: 3
i: 1
t: 1
o: 1
: 1
p: 3
e: 3
r: 1
e: 3
z: 1
What I need is that it only shows for example the P
and how many there are, but not that they are repeated.