I have a database field called "checkOrCardNo" which is defined as varchar2. Some records for this field are only numeric and some of them are alphanumeric. How will I be able to sort out the data? When I use an "order by" clause then I have to sort the string values. I have three values: 54316, 5153, 7134. My display is in the order 5153, 54316, 7134. But I want the result set to be displayed as 5153, 7134, 54316. Can anybody help me regarding this?
When I have run into this situation, I have resorted to a simple trick. Since the data is stored in a character datatype, Oracle uses character-based sorting, not numeric sorting. Which is why 54316 appears before 7134. So my trick is to first sort by the length of the value and then by the value itself:
ORDER BY LENGTH(checkorcardno),checkorcardno
By submitting your personal information, you agree that TechTarget and its partners may contact you regarding relevant content, products and special offers.