Skip to content
Advertisement

ORACLE SQL – ALTER TABLE ORDER BY

I have a table with two columns “COL_A” and “COL_B” which I create by inserting one row at a time:

I would like at the end of the program to have the table ordered by COL_A. I thought this coud be possible by running an ALTER TABLE command after I filled the table so I tried with:

But I get

Of course I could create another table with the data of this original table ordered by COL_A, but I would like to know if I can do it in place.

I am using ORACLE SQL in SAS.

Advertisement

Answer

In SQL, tables represent unordered sets. You can only order the table when you are querying the data:

If you are concerned about performance, you can add an index on (col_a) — so the index is used instead of actually sorting.

Note: The lack of ordering is also true of views. If you want an ordered result set, you need to use order by in the query.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement