Spriggy
Spriggy

Reputation: 3

How can I change the order of the rows in an Oracle Database? (Order By not an option)

How can I reorder rows in oracle sql database? I am using a 3rd party database-driven software and unfortunately I cannot change the call (or I would just add an order by), but can I change the order of the rows in the database?

Disclaimer: I know I should never depend on raw database order, and if it changes I understand, but can this be done?

Thank you!

Upvotes: 0

Views: 1645

Answers (1)

Justin Cave
Justin Cave

Reputation: 231661

You can't. If a query doesn't specify an ORDER BY, the order in which rows are returned is undefined.

If you are willing to accept a less-than-100% solution, you could try moving the data to a temporary table, truncate the table, and then insert the data back in the order you want it to appear. If the query is doing a table scan or some type of index scans and not doing anything complicated (like a join), it's likely that the rows would be returned in the order they are physically stored in the table. No guarantees, of course, but it might work most of the time.

Upvotes: 2

Related Questions