Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9201433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:00:26+00:00 2026-06-17T23:00:26+00:00

I am using Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 I have a table

  • 0

I am using Oracle Database 11g Enterprise Edition Release 11.2.0.2.0

I have a table as follows:

Table1:
Name              Null     Type          
----------------- -------- ------------- 
NAME              NOT NULL VARCHAR2(64)  
VERSION           NOT NULL VARCHAR2(64) 


Table1
Name    Version
---------------
A         1
B         12.1.0.2
B         8.2.1.2
B         12.0.0
C         11.1.2
C         11.01.05

I want the output as:

Name    Version
---------------
A        1
B        12.1.0.2
C        11.01.05

Basically, I want to get the row for each name which have highest version. For this I am using the following query:

SELECT t1.NAME, 
       t1.VERSION
FROM TABLE1 t1 
LEFT OUTER JOIN TABLE1 t2
on (t1.NAME = t2.NAME and t1.VERSION < t2.VERSION)
where t2.NAME is null

Now ‘t1.VERSION < t2.VERSION’ only works in normal version cases but in cases such as:

B         12.1.0.2
B         8.2.1.2

It fails, I need a PL/SQL script to normalize the version strings and compare them for higher value.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:00:27+00:00Added an answer on June 17, 2026 at 11:00 pm

    Just wrote a MySQL user defined function to accomplish the task, you can easily port it to ORACLE PL/SQL.

    DELIMITER $$
    
    DROP FUNCTION IF EXISTS `VerCmp`$$
    
    CREATE FUNCTION VerCmp (VerX VARCHAR(64), VerY VARCHAR(64), Delim CHAR(1))
    RETURNS INT DETERMINISTIC
    BEGIN
        DECLARE idx INT UNSIGNED DEFAULT 1;
        DECLARE xVer INT DEFAULT 0;
        DECLARE yVer INT DEFAULT 0;
        DECLARE xCount INT UNSIGNED DEFAULT 0;
        DECLARE yCount INT UNSIGNED DEFAULT 0;
        DECLARE counter INT UNSIGNED DEFAULT 0;
    
    SET xCount = LENGTH(VerX) - LENGTH(REPLACE(VerX, Delim,'')) +1;
    SET yCount = LENGTH(VerY) - LENGTH(REPLACE(VerY, Delim,'')) +1;
    
    IF xCount > yCount THEN
        SET counter = xCount;
    ELSE
        SET counter = yCount;
    END IF;
    
    WHILE (idx <= counter) DO
    
        IF (xCount >= idx) THEN
            SET xVer = SUBSTRING_INDEX(SUBSTRING_INDEX(VerX, Delim, idx), Delim, -1) +0;
        ELSE
            SET xVer =0;
        END IF;
        IF (yCount >= idx) THEN
            SET yVer = SUBSTRING_INDEX(SUBSTRING_INDEX(VerY, Delim, idx), Delim, -1) +0;
        ELSE 
            SET yVer = 0;
        END IF;
    
        IF (xVer > yVer) THEN
            RETURN 1;
        ELSEIF (xVer < yVer) THEN
            RETURN -1;
        END IF;
    
        SET idx = idx +1;
    END WHILE;
    
    RETURN 0;
    
    END$$;
    
    DELIMITER ;
    

    Few test that I ran:

    select vercmp('5.2.4','5.2.5','.');
    +------------------------------+
    | vercmp('5.2.4','5.2.5','.')  |
    +------------------------------+
    |                           -1 |
    +------------------------------+
    
    select vercmp('5.2.4','5.2.4','.');
    +------------------------------+
    | vercmp('5.2.4','5.2.4','.')  |
    +------------------------------+
    |                            0 |
    +------------------------------+
    
    select vercmp('5.2.4','5.2','.');
    +----------------------------+
    | vercmp('5.2.4','5.2','.')  |
    +----------------------------+
    |                          1 |
    +----------------------------+
    
    select vercmp('1,2,4','5,2',',');
    +----------------------------+
    | vercmp('1,2,4','5,2',',')  |
    +----------------------------+
    |                         -1 |
    +----------------------------+
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

we have written a C# 3.5 client talking to an Oracle database (11g) using
I am developing an application using oracle 11g, Java(struts2) and Hibernate. I have table
We have an Oracle 11g database table with around 35 million rows. We are
I have looked through the whole set of Oracle Database 11g Release 2 (11.2)
I have an oracle 11g database. As I understand it, but have not tried
We are using Oracle 11g database with XMLDB installation. We are having table with
In Oracle Database 10g and Oracle Database Express Edition 11g I have encountered some
Initial Problem I was installing Oracle 11g Release 2 Enterprise edition in Ubuntu 10.04
Using oracle database. Here's how i think the SQLException happens... Say i have two
I have a PHP application using an Oracle XE database. Whenever I add a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.