I have two database columns (datatype varchar) which consists values like below
column 1
--------
1.8.0
1.7.0
9.0
10.0
column 2
--------
121
65
78
On UI I have to merge these two columns and show values like
1.8.0_121
1.8.0_78
The problem is while sorting this combined column shown on UI. Since both the columns are varchar in db order by is happening using string and 121 is coming before 78 which is wrong for ascending order.
As a solution I have used ABS for mysql and to_number for oracle on these columns. MySQL is working fine for both the columns but Oracle to_number is throwing error "Invalid number" for first column since its having value as 1.8.0
Kindly suggest how to deal with this situation using code changes only. As doing database schema change will lead to lot of changes at many systems so don't want to touch that.
Sample table with data
Query with order by clause
SELECT (MAJOR || '_' || MINOR) AS VER
FROM VERSION
ORDER BY MAJOR ASC, MINOR ASC
Results
Corrected query for considering varchar columns as numbers
SELECT (MAJOR || '_' || MINOR) AS VER
FROM VERSION
ORDER BY MAJOR ASC, TO_NUMBER(MINOR) ASC
Corrected results
Till this point its perfectly fine. But the issue is MAJOR column can have values like 9.0 and 10.0 so i want to convert major column also to_number in order by clause so that sorting is proper. But since the values are 1.8.0 its throwing error.
The case which is having issue is




order by lpad(column,3)or to_number(column)