Home » SQL & PL/SQL » SQL & PL/SQL » How to change unconditional select order result (merged)
How to change unconditional select order result (merged) [message #350152] Wed, 24 September 2008 04:24 Go to next message
Tlg13team
Messages: 100
Registered: June 2008
Location: MGL
Senior Member
hi all,
i have a one problem.

select col1, col2
from table1

result:
col1, col2
3 f
4 r
5 a

I don't change SQL statement and I need select order second column?

I want it result:
col1, col2
5 a
3 f
4 r



Re: How to change unconditional select order result [message #350154 is a reply to message #350152] Wed, 24 September 2008 04:34 Go to previous messageGo to next message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Use ORDER BY

please read OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code (See SQL Formatter) and align the columns in result.
Use the "Preview Message" button to verify.
Also always post your Oracle version (4 decimals).

Regards
Michel
Re: How to change unconditional select order result [message #350158 is a reply to message #350154] Wed, 24 September 2008 04:43 Go to previous messageGo to next message
Tlg13team
Messages: 100
Registered: June 2008
Location: MGL
Senior Member
I know "ORDER BY".

Condition is don't change "select col1, col2 from table1" statement. Don't add any additional SQL key word.
Re: How to change unconditional select order result [message #350160 is a reply to message #350158] Wed, 24 September 2008 04:45 Go to previous messageGo to next message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
So you can't do it.

Regards
Michel
Re: How to change unconditional select order result [message #350176 is a reply to message #350160] Wed, 24 September 2008 05:17 Go to previous messageGo to next message
Tlg13team
Messages: 100
Registered: June 2008
Location: MGL
Senior Member
Oh really
Re: How to change unconditional select order result [message #350183 is a reply to message #350176] Wed, 24 September 2008 05:25 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
There is no way of guaranteeing the order of the data without using an ORDER BY clause.
End of discussion.

There are some things you can do that will order teh rows in a certain way in certain circumstances, but none of them can be relied upon as a general solution.

If you do just have 3 rows of data in the table,, you could just do :
CREATE TABLE table_2
AS SELECT * FROM table_1 ORDER BY col_2

If you select from Table_2, the rows should come out in the order you want.
This technique will not work for adding rows to tables with data already in them, may well fail when tables are joined to other tables, and generally should not be used.

Can you explain the problem you're having, and why you can't use an ORDER BY
Re: How to change unconditional select order result [message #350384 is a reply to message #350183] Wed, 24 September 2008 21:12 Go to previous messageGo to next message
Tlg13team
Messages: 100
Registered: June 2008
Location: MGL
Senior Member
I have been using very stupid XX program. This program is generate very complex format *.dat file(*.dat file source by database).

I can't change this program used "SQL statement"
because I haven't XX program source code.

The *.dat file should be sort by one special field.


Re: How to change unconditional select order result [message #350437 is a reply to message #350384] Thu, 25 September 2008 01:15 Go to previous message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
The only thing you can do is to sort the file after it has been generated.

Regards
Michel
Previous Topic: TYPICAL QUESTION
Next Topic: Converting non-partitioned table into partitioned table
Goto Forum:
  


Current Time: Sat Dec 03 10:03:23 CST 2016

Total time taken to generate the page: 0.10101 seconds