【发布时间】:2017-11-09 09:55:16
【问题描述】:
我在select语句中使用了变量city_no,但是我发现使用直接值和变量city_no的结果不同> 甚至他们的价值观也是一样的。当我使用直接值'020'时输出为377,当我使用变量时输出为16。我不知道为什么会有所不同,或者我的选择语句有什么问题?下面是sql代码:
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);
当我将 select 语句的条件改为 n.city_no = '020' 时,输出值变成了 16,实际上我知道 n.city_no 时 count(1) 是 16 = '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);
【问题讨论】:
标签: oracle variables for-loop select plsql