order by a string with number and letter

33 views Asked by At

I want to order by a string in sql that have number in it and I want orderby number as number instead of string these are sample string

enter image description here

I try this but it does not work:

SELECT * FROM testTbl
   ORDER BY REPLACE(code,' ','')
1

There are 1 answers

2
Raúl Pérez López On

You can try this, but I'm not entirely sure that I understand your question or your example.

 SELECT *
FROM testTbl
ORDER BY CAST(REGEXP_SUBSTR(code, '[0-9]+') AS NUMERIC_ORDER);