Currently I'm trying to take a list of values from my table and order them alphanumerically so they appear from number to letters. For example I have this data set
3
8
56
70
90
AK
CN
PP
PQ
W3
0.5
0.6
0.8
040
070
1.2
1.5
1.6
100
150
187
2.8
250
3.0
6.3
800
8mm
And I want it to print 0.5 first and then W3 last. I am using an Lpad to grab the data, but it displays like shown above, with no ordering. Is there a way I can sort these alphanumerically in Oracle SQL?
(The SQL statement)
SELECT *
FROM data_table
ORDER BY LPAD(parameter_type, 10) ASC
OFFSET 0 ROWS FETCH NEXT 1000 ROWS ONLY;
MySQL
Perhaps like this:
First, I use
CASEexpressionREGEXPto check whether the leading value is alphabet or number; if the value starts with alphabet, I assign to1if not I'll assign it to0so it'll be on the top of an ascending order. Then I add a second order where I change thevaldatatype to decimal usingCAST. I put both operation inSELECTto see what the value it return after the filtering. Since the purpose they're inSELECTis for viewing purpose only, you can remove them from the final query so like this should work:Alternatively, if you found those values to be useful and you want to use them, you can simplify the query to something like this:
Demo fiddle
Well, as you may already guess, the answer above was for MySQL and posted before the tag change. Unfortunately, Oracle is not my daily database however in the spirit of not trying to post a wrong answer, I did this:
With the intention of trying to emulate the same idea as the MySQL suggested solution above. Demo fiddle