问题:先插入的数据一定排在后插入数据的前面吗?
我们通过试验来说明问题。
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
--创建表t,有三个字段a,b,c 。其中a长度较小,b、c较长。
SQL> create table t (
2 a int,
3 b varchar2(4000) default rpad('*',4000,'*'),
4 c varchar2(3000) default rpad('*',3000,'*')
5 );
Table created
--向t表插入一条记录。
SQL> insert into t(a) values(1);
1 row inserted
--查看记录
SQL> select a from t;
A
---------------------------------------
1
--再插入一条记录
SQL> insert into t(a) values(2);
1 row inserted
SQL> select a from t;
A
---------------------------------------
1
2
--再插入一条记录
SQL> insert into t(a) values(3);
1 row inserted
SQL> select a from t;
A
---------------------------------------
1
2
3
--前三条记录都是先插入的数据在前,后插入的数据在后。
--再插入一条记录,看看结果如何?
SQL> insert into t(a) values(4);
1 row inserted
SQL> select a from t;
A
---------------------------------------
4
1
2
3
我们看到4是最后插入的,但排在了第一位。
说明:oracle中先插入的数据不一定排在后插入数据的前面。
如果我们希望先插入的数据排在后插入数据的前面,可以使用sequence 等其他的手段。