I have this table with a 'title' field which is varchar2 and I want to select all rows and sort them first by number and then by the alphabet as it normally happens.
For instance, I currently get this using a simple ORDER BY title
in the end:
- Abc
- Def
- 321
But I want this:
- 321
- Abc
- Def
The weird thing is that SQL Developer shows the "right" order, with numbers first. But on my app (PHP using OCI8) it shows numbers last.
Not an Oracle expert, but you are supposed to be able to do it without altering the session with
where you can change the
NLS_SORT=
to fit your needs (here are the list of values)Keep in mind that docs says that this will force table scan, so it might be beneficial to filter them first (but if you are selecting all the table scan is what you are going to use anyway).
The reason why SQL Developer exhibits different behaviour is probably because it changes the session.
the difference in behaviour that you're seeing is probably because of different
NLS_SORT
parameter setting. Consider:You can build a query that should give you the expected result regardless of your
NLS_SORT
session parameter setting, for example: