|
Hi, I have a column where the data contains both alphabets and numbers. Sample data is as follows:
I would like to sort this data and look it as follows:
Any suggestions are welcome. Regards, BI DWH BALA
(comments are locked)
|
|
In fact, why not just sort on the substring expressions?
which would work as long as you kept to that format or we reach the year 10,000. Update: While I'm thinking about it, I should add that you could also sort on a CASE expression. Here's an example:
Now, this probably doesn't produce rows in the order you want:
But this does order by quarter, as opposed to the name of the quarter:
If you did have that ordering problem, it might be worthwhile to have a function "Ordinal_Text_to_Int" that handles the cases to tenth place for you ('First', 'Second',... 'Tenth'). I usually use a technique like this when we have a bunch of status codes ('A','X','E','C'... whatever) and I want to see the output sorted with the most critical status ('E' for error, maybe) first. Thank you Dhatewa. This way seems to be simple and short.
Dec 01 '09 at 02:47 PM
BI DWH BALA
(comments are locked)
|
(I haven't got an Oracle database to hand to test this, so there may be some minor error in syntax, but the approach should be obvious)
(comments are locked)
|
|
You could also use a function.
This worked but I had to re-edit it to post - may require further checking. Yep KillerDBA. This solution also works. But only thing, we need to create a userdefined function to do this. And it will increase the number of fucntion calls. I appreciate your response. Thank you.
Dec 01 '09 at 03:02 PM
BI DWH BALA
True. I have to admit, I don't know the performance implications of using functions heavily, although I think it's not bad. The reason I suggested a function was for flexibility. Suppose, the string wasn't always 11 characters and you had to search back to find the last space before the year or had to do something special to parse the Quarter number. In such a case, the order by clause in your select statement start to get ugly and a function would look much cleaner.
Dec 01 '09 at 03:43 PM
KillerDBA
(comments are locked)
|

