Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Default order of a table / inserted record appears to be at the first row

typerAug 18 2013 — edited Aug 19 2013

I'm confusing with the insert function result and the "default" order of a table while I practice with the employee table, EMP

After inserted a new row into the EMP table, I tried to show the result with SELECT * FROM EMP, and found that the latest inserted record appeared on the first row of the table.

SQL> INSERT INTO EMP (EMPNO, ENAME, JOB) VALUES ('&EMPNO','&ENAME', '&JOB');

Enter value for empno: 1234

Enter value for ename: JIMMY

Enter value for job: MANAGER

old   1: INSERT INTO EMP (EMPNO, ENAME, JOB) VALUES ('&EMPNO','&ENAME', '&JOB')

new   1: INSERT INTO EMP (EMPNO, ENAME, JOB) VALUES ('1234','JIMMY', 'MANAGER')

SQL> SELECT * FROM EMP;

     EMPNO ENAME                JOB                       MGR HIREDATE          SAL       COMM     DEPTNO

---------- -------------------- ------------------ ---------- ---------- ---------- ---------- ----------

     1234 JIMMY                MANAGER

      7369 SMITH                CLERK                    7902 17/12/1980        800                    20

      7499 ALLEN                SALESMAN                 7698 20/02/1981       1600        300         30

      7521 WARD                 SALESMAN                 7698 22/02/1981       1250        500         30

      7566 JONES                MANAGER                  7839 02/04/1981       2975                    20

      7654 MARTIN               SALESMAN                 7698 28/09/1981       1250       1400         30

      7698 BLAKE                MANAGER                  7839 01/05/1981       2850                    30

      7782 CLARK                MANAGER                  7839 09/06/1981       2450                    10

      7788 SCOTT                ANALYST                  7566 19/04/1987       3000                    20

      7839 KING                 PRESIDENT                     17/11/1981       5000                    10

      7844 TURNER               SALESMAN                 7698 08/09/1981       1500          0         30

      7876 ADAMS                CLERK                    7788 23/05/1987       1100                    20

      7900 JAMES                CLERK                    7698 03/12/1981        950                    30

      7902 FORD                 ANALYST                  7566 03/12/1981       3000                    20

      7934 MILLER               CLERK                    7782 23/01/1982       1300                    10

15 rows selected.

Shouldn't it go to the bottom of the table since it was inserted last?

I noticed it was displayed at the first place because the employee number I gave was the smallest; also the empno. is the first column of the table, does this have anything to do with the order? 

I didn't put any ORDER BY clause when I typed in the statements.

Is the table always ordered by the first column, by "default" ?

In addition:  order - Default row ordering for select query in oracle - Stack Overflow

What I found from this link: ".......For obvious reasons, if you create a new table, insert a few rows and do a "select *" without a "where" clause, it will return the rows in the order they were inserted."

This is my first post here, the result posted from the console may be a bit messy...also if the question is too easy or something, my apology, I just started learning.

Thanks !

This post has been answered by Frank Kulash on Aug 18 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 16 2013
Added on Aug 18 2013
6 comments
577 views