PLSQL Procudure (Oracle) Comparing a variable in where clause PLSQL Procudure (Oracle) Comparing a variable in where clause database database

PLSQL Procudure (Oracle) Comparing a variable in where clause


I believe you need to rename or prefix your local variable fid as it unfortunately matches the column name in the table you are querying. The SQL engine is simply comparing fid = fid for each row, which will always be true (excepting nulls, but that's another story). Plus, it's harder to read your code when you have variables named the same as a column.

In PL/SQL there tends to be a convention to prefix local variables with a l_ (for local) so it's clear what the purpose is. However, any name other than a column name will suffice. Try:

l_fid faculty.fid%type := 102;

And then...

SELECT count(*) INTO cnt from class where class.fid = l_fid;

(Plus other appropriate replacements.)