ORDER BY function not working in Oracle

回眸只為那壹抹淺笑 提交于 2019-12-12 19:15:24

问题


I'm using the ORDER BY function as per below to order a simple query by customer id (it was originally party age but that didn't seem to work so I changed it to see if it was the syntax or not).

SELECT   customer_id, customer_name, party_age
FROM     customer
ORDER BY customer_id

The report returns no errors, but when I go to view the report it is not ordered at all. I have tried this using numbers as well (ORDER BY x).

Anyone guide me in the right direction?

EDIT: Customer_id is VARCHAR2(3) with 10 sample data fields ranging from 001 to 010. I have tried converting to an int as suggested below but the results are still the same.


回答1:


Order by works in Oracle. The problem must be that the results you are getting are different from what you expect.

A typical reason for this would be a number that is represented as a string. This would order things as 1, 10, 100, 101, 102 . . . which does not look correct, if you are expecting numeric ordering.

My guess is that the following would work:

 order by cast(customer_id as int)


来源:https://stackoverflow.com/questions/13823629/order-by-function-not-working-in-oracle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!