Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I can sort an array through PL/SQL. But can any one help how can I sort the data of table?
Posted
Updated 24-Nov-14 19:33pm
v2
Comments
Herman<T>.Instance 24-Nov-14 14:13pm    
you don't know how to order by ?
Member 11259912 25-Nov-14 9:26am    
I know how to do it by using "order by" clause by I want to do it by bubble sort algorithm in PL/SQL..

B-Tree indexes are always sorted. It's part of the definition.
What's the problem you're trying to solve?
 
Share this answer
 
Comments
Member 11259912 25-Nov-14 1:06am    
Sorry I meant to say that I want to sort the data of the table...e.g A table like this
Index Data
1 Programming
2 Calculus
3 Maths
I want to sort the data of a this table not the index
Index Data
1 Calculus
2 Maths
3 Programming
The table should be like this then...Please guide me in this regard...
Jörgen Andersson 25-Nov-14 2:57am    
This index, is it the primary key you're referring to by any chance. If that's the case, you're on the wrong track. It should never be changed, in fact it should never be visible to the user.
If it's just an ordering you want you can add that with ROW_NUMBER( ) OVER (ORDER BY Data) as Index
If you want help with the query then update your question using the Improve Question button to the right and add your current query you need help with.
Member 11259912 25-Nov-14 9:24am    
Sir either I am not getting you or you are not getting my question. My question is that I have a table in which countries names are listed now I want to sort the names in alphabetical order. How is it possible to sort these countries names using bubble sort algorithm in PL/SQL?
Jörgen Andersson 25-Nov-14 15:09pm    
If you mean that you want to store the data in order, you can't do it. You can not guarantee that the database inserts in order in ordered blocks, nor that it reads the blocks in order.
Well, that last part isn't entirely true, If you store your data in an Index Organized Table, you're actually storing your data in an actual index and it will be sorted by default. (Note, not stored in order, but read in order)

If you want to sort the data you've fetched in a query using your own stored procedure you can of course do that, but it will certainly be magnitudes slower.

All of this is by the way part of Chris Dates definition of the First Normal Form. http://en.wikipedia.org/wiki/First_normal_form#1NF_tables_as_representations_of_relations

You still haven't said what problem you're trying to solve. :-)
Member 11259912 25-Nov-14 18:05pm    
Yes I want to sort the data of my own stored procedure which I have fetched using bubble sort algorithm. Can u guide me in that? Any piece of code in which the data is sorted?
SQL
These all are under indexes concept
While creating table with primary key it having back end index , based on that process the primary key also working



Refere this links

Clustered and Non-Clustered Index in SQL 2005[^]


http://www.w3schools.com/sql/sql_create_index.asp[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900