... forgot the most import issue
The problem shows when the selection is from a view.
The where condition does not have names contention. It is: select count(*) into <var> from <view_name> where <cond>