473,396 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

problem in Order By

37
Hi
I Have a table like this

code=oracle]

sql> select month from temp;
month
-----------
Apr
May
Jul
Jun
dec
Oct
Feb
Nov
Mar
Sep
Jan
Aug

Now i want the o/p like this
sql>select month from temp;

month
----------
Jan
Feb
Mar
Apr
may
Jun
Jul
Aug
Sep
Oct
Nov
Dec

[/code]


Is there any special function to get the months values in order?
Nov 26 '07 #1
3 1476
amitpatel66
2,367 Expert 2GB
Try this:

Expand|Select|Wrap|Line Numbers
  1. SELECT col1,TO_CHAR(TO_DATE('01-'||col1||'-2007','DD-MON-YYYY'),'MM') col2 FROM
  2. (SELECT 'OCT' AS col1 FROM dual
  3. UNION
  4. SELECT 'FEB' FROM dual
  5. UNION
  6. SELECT 'MAR' FROM dual
  7. UNION
  8. SELECT 'DEC' FROM dual
  9. UNION
  10. SELECT 'JUN' FROM dual
  11. UNION
  12. SELECT 'SEP' FROM dual
  13. UNION
  14. SELECT 'JUL' FROM dual
  15. UNION
  16. SELECT 'AUG' FROM dual
  17. UNION
  18. SELECT 'APR' FROM dual
  19. UNION
  20. SELECT 'JAN' FROM dual
  21. UNION
  22. SELECT 'NOV' FROM dual
  23. UNION
  24. SELECT 'MAY' FROM dual)
  25. ORDER BY col2
  26. /
  27.  
Nov 26 '07 #2
Just you need the following sql to excute; you will get the months as per your order :-

SELECT month FROM temp ORDER BY to_date(month,'MON');
Nov 26 '07 #3
Just you need the following sql to excute; you will get the months as per your order :-

SELECT month FROM temp ORDER BY to_date(month,'MON');


select * from (select to_char(hire_date,mm)aa ,to_char(hire_date,month), aa1 from employees ) a order by aa
Dec 3 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Fnark! | last post by:
I am creating a shopping cart using PHP Version 4.1.2. I am creating and registering a cart object in a session. The cart object contains an array of arrays called $order whose elements are a...
19
by: Lauren Quantrell | last post by:
I have a stored procedure using Convert where the exact same Convert string works in the SELECT portion of the procedure but fails in the WHERE portion. The entire SP is listed below....
9
by: jwedel_stolo | last post by:
Hi I'm creating a dataview "on the fly" in order to sort some data prior to writing out the information to a MS SQL table I have used two methods in order to determine the sort order of the...
8
by: Tom Szabo | last post by:
cTemp = oNode.cName; aStatList = "term"; window.alert(aStatList); -> "term" window.alert(aStatList.length); -> "0" the above code is going to display "term" and "0" ...
5
by: NM | last post by:
Hi All, I am having a peculiar problem. I used to link between intel fortran 7.0 and g++ without any problem. Now the intel compiler is upgraded to version 9.0 and I am getting segmenatation...
11
by: Geoff Jones | last post by:
Hi I have a table that has a column with Date types. I am trying to view certain rows in the table using a DataView. Using the filter, I can view the rows with, for example, the date equal...
20
by: Development - multi.art.studio | last post by:
Hello everyone, i just upgraded my old postgres-database from version 7.1 to 7.4.2. i dumped out my 7.1 database (with pg_dump from 7.1) as an sql-file with copy-commands and to one file using...
2
by: AlexanderDeLarge | last post by:
Hi! I got a problem that's driving me crazy and I'm desperately in need of help. I'll explain my scenario: I'm doing a database driven site for a band, I got these tables for their discography...
4
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category...
28
tdw
by: tdw | last post by:
Hi all, I am trying to add a feature to our database that automates sending emails. When entering a new order, I want the option to send an email to the company the order came from, attaching a...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.