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 8109929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:34:33+00:00 2026-06-06T01:34:33+00:00

I have a table part with a few demo data as below in Oracle

  • 0

I have a table part with a few demo data as below in Oracle DB:

ID    NUMBER     DESCRIPTION
1     T00001     test
2     T00002     test
3     T00003     test
4     T00004     test
5     T00008     test
6     SG0001     test
7     SG0002     test
8     SG0003     test
9     SG0004     test
10    SG0006     test

The column NUMBER defines different category part with different predefined prefix and auto-incremental number suffix. Now in DB there have been some numbers missed so the continuity is broken. I want a SQL query or PL-SQL function with perfect performance to list the missed numbers:

e.g: for the above demo data. the following data should be returned:

 Category1 start with T: T00005,T00006,T00007 
 Category1 start with SG: SG0005

Anybody have ideas?

  • 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-06T01:34:35+00:00Added an answer on June 6, 2026 at 1:34 am

    For SG:

    WITH t AS ( 
        SELECT 
            0 as start_n, 
            p.a as end_n 
        FROM (
            SELECT MAX(TO_NUMBER(SUBSTR("NUMBER", 3))) a FROM Part p2 
            WHERE "NUMBER" LIKE 'SG%') p
    )
    SELECT 
        'SG' || LPAD(r.cur_num, 4, '0') AS missing_expr
    FROM 
        (SELECT t.start_n + level - 1 AS cur_num FROM t CONNECT BY t.start_n + level - 1 <= t.end_n) r
    WHERE 
        NOT EXISTS(
            SELECT * FROM part p WHERE p."NUMBER" = 'SG' || LPAD(r.cur_num, 4, '0')
        )
    ORDER BY missing_expr ASC;
    

    For T:

    WITH t AS ( 
        SELECT 
            0 as start_n, 
            p.a as end_n 
        FROM (
            SELECT MAX(TO_NUMBER(SUBSTR("NUMBER", 2))) a FROM Part p2 
            WHERE "NUMBER" LIKE 'T%') p
    )
    SELECT
        'T' || LPAD(r.cur_num, 5, '0') AS missing_expr
    FROM 
        (SELECT t.start_n + level - 1 AS cur_num FROM t CONNECT BY t.start_n + level - 1 <= t.end_n) r
    WHERE 
        NOT EXISTS(
            SELECT * FROM part p WHERE p.number = 'T' || LPAD(r.cur_num, 5, '0')
        )
    ORDER BY missing_expr ASC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table in data base name train delay, with columns train number(int), DelayTime(int),
I have a database table with a few thousand entries. A part of the
I have a table of data which is generated dynamically with Javascript. Every few
I have a large table with a multi-part index. I need to run several
I have a temporary table that contains a part category and the associated part
I have a Datetime column called CreatedOn in a table. CreatedOn is also part
I have table A in Oracle that has a primary key (id). I need
I am creating a table which I want to have a top part, middle
As part of a recent project, I have created a Cell Table that holds
Here is the most relevant part of my database schema: create table TEST (

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.