【问题标题】:Why aren't rows returned in the order of insertion?为什么不按插入顺序返回行?
【发布时间】:2022-06-11 01:16:16
【问题描述】:

甲骨文 18c:

我有1000行测试数据:

create table lines (id number, shape sdo_geometry);
begin
    insert into lines (id, shape) values (1, sdo_geometry(2002, 26917, null, sdo_elem_info_array(1, 2, 1), sdo_ordinate_array(574360, 4767080, 574200, 4766980)));
    insert into lines (id, shape) values (2, sdo_geometry(2002, 26917, null, sdo_elem_info_array(1, 2, 1), sdo_ordinate_array(573650, 4769050, 573580, 4768870)));
    insert into lines (id, shape) values (3, sdo_geometry(2002, 26917, null, sdo_elem_info_array(1, 2, 1), sdo_ordinate_array(574290, 4767090, 574200, 4767070)));
    insert into lines (id, shape) values (4, sdo_geometry(2002, 26917, null, sdo_elem_info_array(1, 2, 1), sdo_ordinate_array(571430, 4768160, 571260, 4768040)));
    insert into lines (id, shape) values (5, sdo_geometry(2002, 26917, null, sdo_elem_info_array(1, 2, 1), sdo_ordinate_array(571500, 4769030, 571350, 4768930)));
...
end;
/

这里有完整的数据:db<>fiddle

当我选择数据时:

select 
    id,
    sdo_util.to_wktgeometry(shape) 
from 
    lines

...数据没有按照我插入的顺序返回。


SQL Developer / 本地数据库:

db小提琴:

我本来希望 ID #1 是第一行,依此类推。


我知道实际上,我们永远不会依赖表中行的顺序。如果排序很重要,我们将使用order by 对数据进行排序。

但是我还是很好奇,为什么数据不按照插入的顺序返回呢?那里发生了什么?

【问题讨论】:

    标签: oracle select insert oracle18c


    【解决方案1】:

    简短的回答是:表基本上是“堆”,行可以插入到他们想要的任何位置。

    【讨论】:

    • 是的。结果集没有实际的顺序,除非您使用 ORDER BY 子句将其明确包含在查询中。
    猜你喜欢
    • 2012-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-22
    • 1970-01-01
    • 2013-01-02
    相关资源
    最近更新 更多