oracle中选择查询的默认行排序

Default row ordering for select query in oracle(oracle中选择查询的默认行排序)
本文介绍了oracle中选择查询的默认行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Oracle 中,如果未指定order by"子句,则选择查询的默认行顺序是什么.

是吗

  1. 插入行的顺序
  2. 根本没有默认排序
  3. 以上都不是.

解决方案

根据 Tom Kyte 的说法:除非您将order by"添加到查询中,否则您无法对返回的行的顺序发表任何看法.好吧,缺少您不能依赖返回的行的顺序"."

参见这个问题 在 asktom.com.

至于 ROWNUM,它在物理上并不存在,因此无法释放".ROWNUM 是在从表中检索记录后分配的,这就是为什么WHERE ROWNUM = 5"总是无法选择任何记录的原因.

@ammoQ:您可能想阅读 这篇 AskTom 文章 关于 GROUP BY 排序.简而言之:

<块引用><块引用>

在查询中使用 Group By 子句保证输出数据为按分组依据列排序订单,即使没有 Order By条款?

我们说...

绝对不会,

从来没有,从来没有,从来没有会.

In Oracle, what is the the default ordering of rows for a select query if no "order by" clause is specified.

Is it

  1. the order in which the rows were inserted
  2. there is no default ordering at all
  3. none of the above.

解决方案

According to Tom Kyte: "Unless and until you add "order by" to a query, you cannot say ANYTHING about the order of the rows returned. Well, short of 'you cannot rely on the order of the rows being returned'."

See this question at asktom.com.

As for ROWNUM, it doesn't physically exist, so it can't be "freed". ROWNUM is assigned after a record is retrieved from a table, which is why "WHERE ROWNUM = 5" will always fail to select any records.

@ammoQ: you might want to read this AskTom article on GROUP BY ordering. In short:

Does a Group By clause in an Query gaurantee that the output data will be sorted on the Group By columns in order, even if there is NO Order By clause?

and we said...

ABSOLUTELY NOT,

It never has, it never did, it never will.

这篇关于oracle中选择查询的默认行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Sort by ID DESC(按ID代码排序)
SQL to Generate Periodic Snapshots from Transactions Table(用于从事务表生成定期快照的SQL)
MyBatis support for multiple databases(MyBatis支持多个数据库)
Oracle 12c SQL: Missing column Headers in result(Oracle 12c SQL:结果中缺少列标题)
SQL query to find the number of customers who shopped for 3 consecutive days in month of January 2020(查询2020年1月连续购物3天的客户数量)
How to get top 10 data weekly (This week, Previous week, Last month, 2 months ago, 3 month ago)(如何每周获取前十大数据(本周、前一周、上个月、2个月前、3个月前))