Reputation: 101
I am using the following query to get the version:
select version FROM V$INSTANCE;
What I want here is that the output be in integer format, so for 11.0.2.4, it should be 11024.
I tried to_number
as well as regex_substr
but am unable to figure out how I can do this using PL/SQL.
Kindly provide some guidance here.
Upvotes: 0
Views: 713
Reputation: 147166
To avoid collisions between version numbers, you need to
This query works on a table (v
) of sample version numbers (11.0.2.4
, 11.1.11.2
, 11.11.1.2
):
WITH cte AS (
SELECT DISTINCT "version", level AS l, REGEXP_SUBSTR("version", '\d+', 1, level) AS num
FROM v
CONNECT BY REGEXP_SUBSTR("version", '\d+', 1, level) IS NOT NULL
)
SELECT "version", LISTAGG(TRIM(TO_CHAR(num, '09'))) WITHIN GROUP (ORDER BY l) AS "version number"
FROM cte
GROUP BY "version"
Output (for the sample data)
version version number
11.0.2.4 11000204
11.1.11.2 11011102
11.11.1.2 11110102
Upvotes: 1
Reputation: 175706
You could use REPLACE
:
select TO_NUMBER(REPLACE(version, '.', '')) FROM V$INSTANCE;
Beware of potential collisions.
Examle: 11.1.11.2
and 11.11.1.2
give the same output 111112
.
Upvotes: 0