Oracle版本是Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production插入了10000条具有相同名称值的记录,然后按名称排序,pageSize为1000,最终可以成功获得10000个id。所以看起来排序是稳定的。
插入sql:
@Insert("insert into org_info(isvalid, update_time, org_uni_code,ORG_CHI_NAME) values(#{isvalid}, TO_TIMESTAMP(#{updateTimeStr}, 'yyyy-mm-dd hh24:mi:ss.ff'), #{orgUniCode},#{name})")
void insertOrgInfo(int isvalid, String updateTimeStr, Long orgUniCode, String name);查询sql:
@Select("select org_uni_code from (" +
" select org_uni_code, rownum rn from(" +
" select org_uni_code from org_info where update_time >= TO_TIMESTAMP(#{updateTimeStr}, 'yyyy-mm-dd hh24:mi:ss.ff') order by ORG_CHI_NAME" +
" )" +
" ) where rn > #{start} and rn<=#{end}")
List<Long> pagingGetOrgUniCodeList(String updateTimeStr, int start, int end);发布于 2019-11-03 03:31:34
Oracle数据库排序不稳定;插入数据的方式与返回数据的方式没有保证的关系。
(请注意,sort stability表示当请求的排序顺序中存在ties时,将保留原始顺序。询问Oracle是否具有稳定的排序与询问更常见的问题“Oracle是否会以插入的顺序返回行?”稍有不同。)
很多时候,Oracle排序看起来很稳定,但很容易构建演示不稳定排序的测试用例。如果我们想要有保证的排序行为,我们必须在ORDER BY子句中完全指定表达式。
例如,下面这个简单的测试用例以1、2、3的顺序为B列插入了值,但在按A排序时,它以1、3、2的顺序返回了B值。
--drop table table1;
create table table1(a number, b number);
insert into table1 select 1,1 from dual;
insert into table1 select 1,2 from dual;
insert into table1 select 1,3 from dual;
select * from table1 order by a;
A B
- -
1 1
1 3
1 2确切的算法没有文档记录,因此这种行为可能不容易重现。但是,如果你尝试过足够多的排序,你会很容易找到不稳定排序的例子。
https://stackoverflow.com/questions/58668333
复制相似问题