I was using a variable city_no in the select statement, but I found that the result is different between using direct value and the variable city_no even their values is the same one. The output was 377 when I used the direct value '020', and 16 was the output when I used the variable . I don't know why is different or is there any problem with my select statment ? below is the sql code :
city_no:='020';
need_kinds := 0;
for need_item in (select n.rootcode, n.need2018, n.got2018
from jq_temp_hy_need_2018 n
where n.city_no = city_no
and (n.need2018 - n.got2018) > 0) loop
current_need_map(need_item.rootcode) := need_item.need2018 -
need_item.got2018;
already_get_map(need_item.rootcode) := need_item.got2018;
need_kinds:=need_kinds+1;
end loop;
-- out put 377
dbms_output.put_line(need_kinds);
when I changed the condition of select statement to n.city_no = '020' , the output value became 16, actually I know the count(1) is 16 when n.city_no = '020' .
city_no:='020';
need_kinds := 0;
for need_item in (select n.rootcode, n.need2018, n.got2018
from jq_temp_hy_need_2018 n
where n.city_no = '020'
and (n.need2018 - n.got2018) > 0) loop
current_need_map(need_item.rootcode) := need_item.need2018 -
need_item.got2018;
already_get_map(need_item.rootcode) := need_item.got2018;
need_kinds:=need_kinds+1;
end loop;
-- out put 16
dbms_output.put_line(need_kinds);