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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:53:39+00:00 2026-06-03T22:53:39+00:00

I have a table mytable in ORACLE database having only one column Roll_no like

  • 0

I have a table mytable in ORACLE database having only one column Roll_no like following:

Roll_no
----------
CD01 0001
CD01 0002
CD01 0004
CD01 0005
CD01 0008

here CD01 is fixed, after CD01 one space is there and then numbers are written 0001 and onwards.

Please see here that CD01 0003, CD01 0006, CD01 0007 are missing and these are my required output.

Required output:

Roll_no
----------
CD01 0003
CD01 0006
CD01 0007

How can I write a SQL query to find out these missing alphanumeric characters? Any ideas please

  • 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-03T22:53:41+00:00Added an answer on June 3, 2026 at 10:53 pm

    You could generate the full list of number and then with a NOT EXISTS (or NOT IN) filter the existing records out. For example:

    SELECT new_roll_no
      FROM (SELECT 'CD01 ' || to_char(rownum, 'fm0000') new_roll_no FROM dual 
            CONNECT BY LEVEL <= (SELECT to_number(MAX(substr(roll_no, 6))) FROM T))
     WHERE new_roll_no NOT IN (SELECT roll_no FROM T)
     ORDER BY 1
    

    Here’s how it works:

    • CONNECT BY LEVEL is a bit of a trick query, it will generate rows up to the level you indicate (in this case I chose the max from your table). I think this query first appeared on the askTom site and is now quite widespread.
    • I’ve generated 8 rows, I will next use the TO_CHAR function to make a column look like your primary key (see the format model documentation of the TO_CHAR function).
    • I then compare these generated values to your actual table value (NOT IN is an ANTI-JOIN)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 3 columns in Oracle database having table mytable and i want records
I am using oracle 10g EE database.I have one table mytable and has two
I have a string from oracle table like this: SELECT col1 FROM MyTable; col1
For example I have a table MyTable like this: Id Value Rate 1 10
In my Oracle db I have records like this one: <ROOT> <Event> <Type>sldkfvjhkljh</Type> <ID>591252</ID>
I have an Oracle Date column in a db table, and fetching this field
Suppose that, I use Oracle database. If my table have a lot of data
In Oracle, I have a table called MyTable. This table has columns 'A' and
I have table, MyTable, in Oracle 11GR2: COL1 VARCHAR2 COL2 VARCHAR2 COL3 VARCHAR2 COL4
I have rows in an Oracle database table which should be unique for 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.