-1
I am studying PL/SQL on my own account and I am having a lot of difficulty, I would like to tell you how I can improve the code below. I’m using the logic of wanting to pull and count every time the letter "M" appears in the table below. It’s just that you’re making a mistake on the Else part, if anyone has any tips on how to improve the code, or how best to do this.
`declare
contador NUMBER;
contador2 NUMBER;
begin
SELECT SEX FROM EMPLOYEE;
contador := 0;
contador2 := 0;
if EMPLOYEE.SEX = 'M'
then loop
contador := contador + 1;
else
contador := contador2 + 1;
end if;
end loop;
DBMS_OUTPUT.PUT_LINE('Numero de sexo Masculino é', contador,
'Numero de sexo feminino é', contador2);
end`
do not program in pl/sql, however, seeing the documentation, the IF structure does not seem to have this
loop
.– ThRnk
the loop is not really part of it, but it is allowed by pl/sql to loop inside IF’s and Else, in which case I used it because I am increasing the counters to know how many times M or F appears inside the column
– beta_carlin
maybe on the line
contador := contador2 + 1
shouldn’t becontador2 := contador2 + 1
?– ThRnk
I think you are mistakenly considering that your loop will run through the lines resulting from the select. See cursor or, better yet, use an aggregation function in select.
– anonimo
I managed to settle here with FOR with the help of a staff of my company, I will post the code
– beta_carlin
but thanks for the help and tips
– beta_carlin