In Oracle 11g, how to change the order of the results of a sql without “order by”?(转)

oracle 11g

当sql语句中不加order by的时候,好像是按rowid的顺序返回结果的。
我也看过一些相关的文档,oracle的官方意思就是不加order by,就不保证输出的顺序

那么,问题来了:
如果现在我select XXX,一组结果出来,顺序是.......A....B.....
那么接下来我做什么操作,再做同样一句select,怎么才能让结果变成....B...A.....
Notice1: 操作中请勿修改表的主键,不要用DDL,只用select * from A;得到结果
Notice2:
create table A(id NUMBER(20) primary key, name VARCHAR2(30));
insert into A values(1,'one');
insert into A values(2,'two');select * from A;

这个问题我试验了一些操作,比如update,insert,delete一两条数据啊,都不能做到改变两个结果的相对顺序。

 

 

Given this requirement:

Do not change the SQL select * from table A. 
Change the table A to change the results order

the answer is a clear and definite: this is not possible.



(Keeping my initial answer as a reference)

"I know the results will be sorted by rowid" - no, they are not.

The rows will be returned in any order the database thinks is the most efficient.

There is no, absolutely no, guarantee that rows are returned in any specific order unless you specify an ORDER BY.

The ONLY way to get a specific order is to use an ORDER BY.

 

http://stackoverflow.com/questions/20186673/in-oracle-11g-how-to-change-the-order-of-the-results-of-a-sql-without-order-by

 

rowid是标识行的唯一性,格式:data object number(6个字符)+relative file number(3个字符)+block number(6个字符)+row number(3个字符)
数据库的理论基础就是集合论,本质上就是无序的,不使用order by(子查询或查询)是不能保证顺序,你把数据不停无序删除再加回估计就能看到这个现象,但大部分时候都是在磁盘上的次序,这跟数据库怎么读数据有关

http://zhidao.baidu.com/link?url=F6VOk6Khxty3AmU9CgVRrdaBf7UBSsQU6wKLnmqE2XxQ75P_4nTtqYMARQAGOJk6q-cTYxXK1jiiaYQT1DHaGvEBdYo9mj571VrusfBd2JO

 

时间: 2024-07-29 07:15:20

In Oracle 11g, how to change the order of the results of a sql without “order by”?(转)的相关文章

Oracle 11g新特性之收集多列统计信息

        通常,当我们将SQL语句提交给Oracle数据库时,Oracle会选择一种最优方式来执行,这是通过查询优化器Query Optimizer来实现的.CBO(Cost-Based Optimizer)是Oracle默认使用的查询优化器模式.在CBO中,SQL执行计划的生成,是以一种寻找成本(Cost)最优为目标导向的执行计划探索过程.所谓成本(Cost)就是将CPU和IO消耗整合起来的量化指标,每一个执行计划的成本就是经过优化器内部公式估算出的数字值.         我们在写SQ

oracle 11g order by 多音字的问题

问题描述 oracle 11g order by 多音字的问题 比如一个字段存 北京 上海 重庆 , 正常排序北京 重庆 上海 , 但是oracle把chongqing看成zhongqing , 排到最后了, 请问有解决办法吗, 解决方案 oracle 分页 order by 问题oracle 11g rac ORA-01105: mount is incompatible with mounts by other instancesOracle 11g的新特性----By Burleson C

基于同一主机配置Oracle 11g Data Guard(logical standby)

      Oracle Data Guard逻辑备库是利用主库的一个备份首先建立一个物理备库,然后再将其转换为逻辑备库.这之后主库将日志传递到备库,备库利用logminer从主库的日志中解析出主库所执行过的SQL,在备库上重新执行一遍,从而保证与主库的数据在逻辑上保持一致.与物理备库相对应的是,物理备库使用的是redo apply,逻辑备库使用的是sql apply.因此逻辑备库仅仅保证数据与主库是在逻辑上是一致的,从而逻辑备库可以处于open状态下并进行相应的DML操作.本文描述了创建逻辑备

centos install oracle 11g rpm Express edition

Install Oracle 11g Express (XE) on CentOS This post will cover basic installation and configuration of Oracle 11g Express Edition (XE) on CentOS. We will also take a quick look at configuring Application Express (APEX) for 11g XE. Basic installation

Oracle 11g 新特性 -- Online Patching (Hot Patching 热补丁)说明

Oracle 11g 新特性 -- Online Patching (Hot Patching 热补丁)说明 一.官网说明 MOS 的文档:RDBMSOnline Patching Aka Hot Patching [ID 761111.1] 有说明.这里取部分内容.   A regular RDBMSpatch is comprised of one or more object (.o) files and/or libraries (.afiles). Installing a regul

oracle 11g数据库中SPA使用例子介绍

oracle 11g推出了新特性SPA(SQL performance Analyze)现在已经被广泛应用到升级和迁移的场景中,当然比如一些其他的场景也可以考虑使用,比如(优化器参数修改.IO子系统变更等),这种功能可向DBA 提供有关SQL语句性能的详细信息,例如,执行前后的统计信息,提高或降低性能的语句,主要用于衡量环境变化后SQL执行性能是否出现衰变等. SPA的主要实施步骤如下: 1 在源环境捕捉SQL负载,生成SQLSET exec dbms_sqltune.create_sqlset

Centos6 下Oracle 11g R2 安装

1准备 CentOS-6.5-x86_64-bin-DVD1 linux_11gR2_database_1of2 linux_11gR2_database_2of2 VMware Workstation 10.0.2 SSH Secure Shell Client instantclient_11_2 plsqldev10052安装虚拟机及CentOS (1)安装VMware Workstation (2)安装CentOS,主机命名为:oracledb (3)磁盘需要大于30G(经验值) (4)

What is SCAN in Oracle 11g R2 RAC

What is SCAN in Oracle 11g R2 RAC Single client access name (SCAN) is meant to facilitate single name for all Oracle clients to connect to the cluster database, irrespective of number of nodes and node location. Until now, we have to keep adding mult

基于同一主机配置 Oracle 11g Data Guard

       Oracle Data Guard 为企业数据库提供了最有效和最全面的数据可用性.数据保护和灾难恢复解决方案.它集成管理.监视和自动化软件基础架构来创建和维护一个或多个同步备用数据库,从而保护数据不受故障.灾难.错误和损坏的影响.本文主要描述了在同一主机下如何配置Oracle Data Guard.               有关DG的相关概念,可参考:Oracle Data Guard Concepts and Administration        有关配置DG的参数描述