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-30 07:16:14

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

Oracle 11g数据库详解(2015-1-18更新)

Oracle 11g数据库详解 整理者:高压锅 QQ:280604597 Email:[email protected] 大家有什么不明白的地方,或者想要详细了解的地方可以联系我,我会认真回复的 1   简介 数据库操作主要有以下几步: 1.  启动.停止数据库 2.  连接.断开数据库 3.  创建.修改.删除数据库用户 4.  表空间 5.  新建.修改.删除表 6.  查询.插入.修改.删除表数据 7.  新建.修改.删除视图 8.  新建.修改.删除存储过程 9.  新建.修改.删除触发

Oracle 11g单实例RMAN恢复到Oracle 11g RAC

一.环境说明 操作系统版本: RHEL 6.5 x64 1. 源数据库服务器 Oracle版本: Oracle 11g 11.2.0.4 64位(单机)Oracle_SID: orcl db_name   : orcl 背景:一台生产oracle10g(10.2.0.5)数据库计划迁移到Oracle 11.2.0.4.0 RAC.1) 先oracle10g(10.2.0.5)升级到Oracle 11.2.0.4(过程略)2)再Oracle 11.2.0.4单实例迁移到Oracle 11.2.0.

Oracle 11g数据库详解(2015-02-28更新)

Oracle 11g数据库详解 整理者:高压锅 QQ:280604597 Email:[email protected] 大家有什么不明白的地方,或者想要详细了解的地方可以联系我,我会认真回复的 1   简介 数据库操作主要有以下几步: 1.  启动.停止数据库 2.  连接.断开数据库 3.  创建.修改.删除数据库用户 4.  表空间 5.  新建.修改.删除表 6.  查询.插入.修改.删除表数据 7.  新建.修改.删除视图 8.  新建.修改.删除存储过程 9.  新建.修改.删除触发

Oracle 11g 虚拟列 Virtual Column介绍

Oracle 11G 虚拟列 Virtual Column Oracle 11G 在表中引入了虚拟列,虚拟列是一个表达式,在运行时计算,不存储在数据库中,不能更新虚拟列的值. 定义一个虚拟列的语法: column_name [datatype] [GENERATED ALWAYS] AS [expression] [VIRTUAL] 1.虚拟列可以用在select,update,delete语句的where条件中,但是不能用于DML语句 2.可以基于虚拟列来做分区 3. 可以在虚拟列上建索引,o

Zero Downtime Upgrade of Oracle 10g to Oracle 11g Using GoldenGate — 3

DDL Setup Steps SQL> grant execute on utl_file to ggs; Grant succeeded. Create GLOBALS file [[email protected] ~]$ cd /ggs/ [[email protected] ggs]$ cat GLOBALS GGSCHEMA GGS run marker_setup.sql [[email protected] ggs]$ sqlplus / as sysdba SQL*Plus:

Oracle 11g trace events

oracle的events,是我们在做自己的软件系统时可以借鉴的 Oracle 11g trace eventsORA-10001: control file crash event1ORA-10002: control file crash event2ORA-10003: control file crash event3ORA-10004: block recovery testing - internal errorORA-10005: trace latch operations fo

Linux静默安装Oracle 11g教程

准备工作 在电脑中下载 linux.x64_11gR2_database_1of2.zip 和 linux.x64_11gR2_database_2of2.ziphttp://download.oracle.com/otn/linux/oracle11g/R2/linux.x64_11gR2_database_1of2.ziphttp://download.oracle.com/otn/linux/oracle11g/R2/linux.x64_11gR2_database_2of2.zip复制链

ORACLE 11G DataGuard的一些高级管理案例研究

搭建完了ORACLE 11G dataguard后,也做了角色切换的实验,有switchover已经failover,感觉受益颇多,而后继续研究了下dataguard的一些高级管理功能,所谓冰山一角,ORACLE果然博大精深,总结记录如下:1,ORACLE 11G dataguard的高级管理1.1.READ ONLY/WRITE模式打开物理STANDBY一般standby都是可以设置为mount状态的,于物理standby 可以有效分担primary 数据库压力,提升资源利用,实际上说的就是这

Linux平台oracle 11g单实例 安装部署配置 快速参考

1.重建主机的Oracle用户 组 统一规范 uid gid 以保证共享存储挂接或其他需求的权限规范 userdel -r oracle groupadd -g 500 oinstall groupadd -g 501 dba useradd -g oinstall -G dba -u 500 oracle #id oracle uid=500(oracle) gid=500(oinstall) 组=500(oinstall),501(dba) 2.安装好Oracle 需要的rpm包.安装rpm