1

Is it possible to sort the data inside of an oracle table? Like ascending/descending via a certain column, alphabetically. Oracle 10g express.

5 Answers 5

4

You could try

Select *
from some_table
order by some_column asc

This will sort the results by some_column and place them in ascending order. Use desc instead of asc if you want descending order. Or did you mean to have the ordering in the physical storage itself?

I believe it's possible to specify the ordering/sorting of an indexed column in storage. It's probably closest to what you want. I don't usually use this index sort feature, but for more info see: http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_5010.htm#i2062718

Sign up to request clarification or add additional context in comments.

3 Comments

Physical storage itself, is it possible?
@Jacob: Updated, added a link to the CREATE INDEX statement specs which show how the index can be ordered in storage.
I could be wrong but I think that the OP was referring to the storage order of the table data itself rather than an index
3

Perhaps you could use an index organized table - IOT to ensure that the data is stored ordered by index.

Have a look at the physical properties clause of the CREATE TABLE statement: http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_7002.htm#i2128663

What is the problem that you are trying to solve though? An IOT may or may not be what you should be using.

Comments

1

As defined by the relational model, the rows and columns in a table are unordered. That's the theory at least.

In practice, if you want the data to come out of a query in a particular order then you should always use the ORDER BY clause. The order of the output is not guarantee unless you provide that.

It would be possible to use an ORDER BY when inserting into a table but that doesn't guarantee the order that data will be output. A query might come out in the same order every time.... but that doesn't mean it will come out in the same order next time.

There were issues when Oracle 10g came out where aggregate queries (with GROUP BY) were not coming out sorted because users had come to rely on the data being sorted as a side-effect of the grouping. With the introduction of the HASH GROUP BY in addition to the SORT GROUP BY people were caught out. This was a useful reminder that ORDER BY should always be used.

1 Comment

what if ORDER BY is not an option? It takes too long in my case
0

What do you really mean ?

Are you just asking for the order by clause ?

http://www.1keydata.com/sql/sqlorderby.html

2 Comments

No I mean the actual data in the table.
What's the purpose ? an index seems to be the closer answer to your weird question.
0

Oracle 10g Express supports ANSI SQL like most RDBM's so you can sort in the standard manner:

SELECT * FROM Persons ORDER BY LastName

A good tutorial on SQL can be found here: w3schools SQL

Oracle Express does have some limitations compared to the Enterprise Edition but not in the basic SQL dialect it supports.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.