【发布时间】:2018-04-13 20:14:03
【问题描述】:
我有一个包含 10 000 000 个随机数的表。该语句在大约 2 秒内执行(不创建索引)'select count(1) from myTableName where x + 200
declare
cursor example is
select count(1) countOf from padure where x + 200 < 500;
begin
for i in example loop
dbms_output.put_line(i.countOf);
end loop;
end;
我在 0.2 秒内执行了所有块,但是,如果我这样做:
declare
nbr constant integer := 200;
cursor example is
select count(1) countOf from padure where x + nbr < 500;
begin
for i in example loop
dbms_output.put_line(i.countOf);
end loop;
end;
我在大约 2 秒内得到结果。 当我改用变量时,为什么它需要这么多时间才能执行此查询? 我怎样才能避免这种情况?或者如何实现与第一个示例相同的执行时间?
【问题讨论】:
标签: oracle plsql database-indexes