How to find Missing Numbers, simplest way

Hi All,
Table 1
Invoice_books_issues
Columns are Transaction_date,serail_no_start,serial_no_end.
Ex Data is :
1/1/2005...........1000.............2000
2/2/2005...........4500.............5500
My Invoice_table is
Inv_no
1908
1005
4502
4589
5509......on and on...
so i need to get the missing nos out of the issues. like
1000
1001
1002
1003
1004 ... note here 1005 alrady been used.
1006
... on and on.
Thanks in advance.

something like this :
1. create view holding surrogate numbers:
CREATE OR REPLACE VIEW NUM_VIEW
(NUM)
AS
SELECT thous.x+huns.x+tens.x+ones.x num FROM
(SELECT 0 x FROM dual
UNION SELECT 1 FROM dual
UNION SELECT 2 FROM dual
UNION SELECT 3 FROM dual
UNION SELECT 4 FROM dual
UNION SELECT 5 FROM dual
UNION SELECT 6 FROM dual
UNION SELECT 7 FROM dual
UNION SELECT 8 FROM dual
UNION SELECT 9 FROM dual) ones,
(SELECT 0 x FROM dual
UNION SELECT 10 FROM dual
UNION SELECT 20 FROM dual
UNION SELECT 30 FROM dual
UNION SELECT 40 FROM dual
UNION SELECT 50 FROM dual
UNION SELECT 60 FROM dual
UNION SELECT 70 FROM dual
UNION SELECT 80 FROM dual
UNION SELECT 90 FROM dual) tens,
(SELECT 0 x FROM dual
UNION SELECT 100 FROM dual
UNION SELECT 200 FROM dual
UNION SELECT 300 FROM dual
UNION SELECT 400 FROM dual
UNION SELECT 500 FROM dual
UNION SELECT 600 FROM dual
UNION SELECT 700 FROM dual
UNION SELECT 800 FROM dual
UNION SELECT 900 FROM dual) huns,
(SELECT 0 x FROM dual
UNION SELECT 1000 FROM dual
UNION SELECT 2000 FROM dual
UNION SELECT 3000 FROM dual
UNION SELECT 4000 FROM dual
UNION SELECT 5000 FROM dual
UNION SELECT 6000 FROM dual
UNION SELECT 7000 FROM dual
UNION SELECT 8000 FROM dual
UNION SELECT 9000 FROM dual) thous
this one holds numbers up to 9999 - should be up to the maximum value for your invoice number.
2.
CREATE TABLE INVOICE
INV_NO NUMBER(5)
Insert into invoice
(INV_NO)
Values
(1000);
Insert into invoice
(INV_NO)
Values
(4501);
Insert into invoice
(INV_NO)
Values
(4505);
COMMIT;
3.
CREATE TABLE INVOICE_BOOKS_ISSUES
SERIAL_NO_START NUMBER,
SERIAL_NO_END NUMBER
Insert into INVOICE_BOOKS_ISSUES
(SERIAL_NO_START, SERIAL_NO_END)
Values
(1000, 1006);
Insert into INVOICE_BOOKS_ISSUES
(SERIAL_NO_START, SERIAL_NO_END)
Values
(4500, 4507);
COMMIT;
4.
SQL> select * from invoice;
INV_NO
4501
1000
1005
4505
SQL> select * from Invoice_books_issues;
SERIAL_NO_START SERIAL_NO_END
1000 1006
4500 4507
SQL>
select num
from num_view nv
where exists
(select serial_no_start, serial_no_end from Invoice_books_issues ibi
where nv.num >= ibi.SERIAL_NO_START and nv.num <= ibi.SERIAL_NO_END)
and
not exists (select inv_no from invoice inv where inv.INV_NO = nv.num)
NUM
1001
1002
1003
1004
1006
4500
4502
4503
4504
4506
4507
11 rows selected.
SQL>
hope this helped.
Mike

Similar Messages

  • Finding Missing Numbers

    I want to find missing numbers from a column which is alpha numeric, its last five positions are numeric. At first three positions there are different combinations of alphas i.e. *'BA ','BAW','SA ','SAA' ..........* if alphas are two then 3rd position is blank. I also need it to generalised this to cover all existing alpha numeric series.
    SELECT SUBSTR (a.claim_no, 4, 5) + 1
      FROM core_business.cb_pensioner a
    WHERE SUBSTR (a.claim_no, 1, 3) = 'BA '
       AND NOT EXISTS (
                     SELECT NULL
                       FROM core_business.cb_pensioner b
                      WHERE to_number(SUBSTR (b.claim_no, 4, 5)) =  to_number(SUBSTR (a.claim_no, 4, 5)) + 1)
       order by SUBSTR (a.claim_no, 4, 5);I am getting ORA-01722 error

    You have two issues with such a task.
    Problem 1 is how to convert the trailing part into a number so that you can compare values.
    to_number(SUBSTR (b.claim_no, 4, 5)) works, but only if the value in b.claim_no is always a number regardless of the other column criteria.
    A statement like
    WHERE SUBSTR (a.claim_no, 1, 3) = 'BA ' /* filter 1 */
    and to_number(SUBSTR (b.claim_no, 4, 5)) > 1 /* filter 2 */
    ...might fail because your table might have a value like
    b.claimno = 'XYZ1234b'
    The way you wrote the query the database will decide which filter criteria it executes first. It might be filter1, but could also be filter2. If filter2 is executed first then you will get the error message.
    Problem 2 how to order and compare different rows, so that you can find the missing values.
    Here the analytic LEAD(LAG) function is very helpful. it will give you access to the next (or previous row).
    Both problems can be overcome.
    Here is my try, but I'm not sure if it works in your case. You might need to adapt a little.
    This should work if all the rows are numeric that belong to the specific groups. if you can have wrong data in there too, then a different approach is needed.
    with testdata as (select 'XYZ1234b' claim_no from dual union all
                select 'BA 12345' claim_no from dual union all
                select 'BA 12346' claim_no from dual union all
                select 'BA 12350' claim_no from dual union all
                select 'BAW11111' claim_no from dual union all
                select 'BAW11113' claim_no from dual union all
                select 'XYZ1234b' claim_no from dual )
    /* end of test data creation */
    select claim_no, substr(claim_no, 1,3) part1, substr(claim_no, 4) part2,
           to_number(substr(claim_no, 4)) current_num,
           lead(to_number(substr(claim_no, 4))) over (partition by substr(claim_no, 1,3) order by to_number(substr(claim_no, 4))) next_num,
           lead(to_number(substr(claim_no, 4))) over (partition by substr(claim_no, 1,3) order by to_number(substr(claim_no, 4)))
            - 1 - to_number(substr(claim_no, 4))
            as "missing_values"
    from testdata
    where substr(claim_no, 1,3) in ('BAW','BA ')
    order by claim_no;
    CLAIM_NO PAR PART2 CURRENT_NUM   NEXT_NUM missing_values
    BA 12345 BA  12345       12345      12346              0
    BA 12346 BA  12346       12346      12350              3
    BA 12350 BA  12350       12350
    BAW11111 BAW 11111       11111      11113              1
    BAW11113 BAW 11113       11113Problem 1 is solved because the where condition is always executed before the function in the select clause, especially in connection with an analytic function.
    Problem 2 is also solved by using the analytic function LEAD function. And this is fast, because you access the same table only one time. Other solution might do a subquery to fetch the value from the previous/next row. This means several accesses to the same table and is usually much slower.
    Edited by: Sven W. on Sep 20, 2010 2:32 PM

  • How to find Missing Parts for a particular Process Order?

    Hi,
    How to find Missing Parts  for a particular Process Order ?
    Is there any function module or Table ??
    Thnx in Advance.

    Hi prince roy
    you can use the T-code = <b>CO24 - Missing Parts Info System</b>
    if helpful PLEASE REWARD YOUR POINTS
    thanks
    chakri

  • How to find Port numbers used by RMI application

    Hi, hope u all find me a solution, how to find port numbers used in the RMI application, that is port number which the RMI application communicates between RMIserver and RMIclient. ur answers would b highly appreciated

    Currently RMI transport layer does not directly expose any public methods to get the listening ports of the exported RMI objects, but the application can always export RMI server objects at certain designated ports instead of relying on the RMI runtime by specifying them to UnicastRemoteObjcect at the time of exporting.
    RMI transport layer try to optimize the number of listeing sockets by exporting all RMI server objects on a single port if no explicit ports were chosen. If the application is really interested in knowing the listeing ports, it can always specify the client and server socket factories to be used for creating Socket and ServerSocket to the RMI runtime at the time of exporting. When a RMI server object is exported, but the listening socket is not yet created, RMI transport layer invokes the createServerSocket(host, port) of server socket factory by passing the host and port details. If no explicit port is specified, underlying socket implementation choses anonymous port. At this point of time application can log these listeing ports to some log file.
    Similarly when the stub to the remote object is de-serialized in the client address space, it does also contain the client socket factory along with the end point details (host, port and server object ID). RMI runtime in the client address space needs to establish connection with the remote server object, it try to get the socket from client socket factory by invoking createSocket() on the client socket factory. Now the application can call getLocalPort() on the socket before returning it to the RMI transport layer.
    There is a undocumented class RMIStat to dump RMI runtime state information. It provides a lot of static methods to dump RMI state information like object table, transports, threads etc. You can download the source code of this utility from RMI archives, but remember this is not a comman-line utility, you must invoke these static methods as part of the application code.
    -- Srinath Mandalapu

  • Find missing numbers in array

    HI !
    I have an array which holds 999 different numbers between 1-1000
    (which means that 1 number between 1-1000 does not appear in the array).
    I need to find the missing number in one pass and it's easy.
    My question is:
    Do you have any idea how can I find 2 missing numbers in the array ?
    Is it possible ?
    I cant use any data structure and I need to find the missing numbers in one pass.
    Thank you

    Using array.sort() and using another array is out of the question as its inhrently banned in the "i cant use any data structure" so this is
    Homework! tut tut
    ok so far an array with 1 number missing "its easy" yeah, just add em all up and see whats missing.
    for 2 numbers missing you should take a hint from what you are studying in the course ie solving Quadratic Equations..
    shall i make snoopy beg yet??
    naw, ok here goes
    on your 1 permitted pass add up all the mumbers that are there, also have another total for the squares of the numbers
    call the numbers you are looking for A and B
    subtract the first total from what it would be if there were all 1000, call this N
    subtract the second total from what the total of the squares would be if there were all 1000, call this M
    so..
    A+B=N
    solve for B in terms of A
    so..
    B=N-A
    and A^2+B^2=M
    should i quit now???
    no, ok
    substitute B in the second equation, shuffle a bit and..
    2A^2-2NA+N^2-M=0
    recognise the terms of the quadratic and..
    A=(2N +/- (4N^2-8(N^2-M))^.5)/4
    note the +/- plus OR minus will give you 2 results, these will be the 2 missing munbers
    tahh dahh
    See maths does have some use

  • How to find missed data

    hi friend,
    i did not find the data for the last two days in the info provider manage screen and in the process chain maintanance also.
    we r getting data from crm and r/3
    can anyone help me how to find the missed records?
    Thanks in advance
    sridath

    Hi,
    The first step is to check in the extractor checker (RSA3) in the source system...
    Then you ahve to check the delta queue...also the missing of record can happen on the delta option that you have chosen...generally unserialized V3 update is preferred so that we do not miss any records....
    Thanks
    santo

  • How to find missing tool

    how to find my missing tone curve tool in my develop module

    Right-click on "Basic", then place a check mark next to "tone curve"
    Please type in a bigger font next time, like the size of this sentence.

  • How to find missing glyphs / characters

    hi,
    is there a way to find missing glyphs / characters (that are not contained in a font and thus displayed as pinkish rectangles) in a text?
    I thought there might be a metacharacter or a variable of the Text object, but I couldn't find anything.
    thanks,
    w

    Try scripting a preflight check

  • How to find Delivery numbers for a range of Material Documents

    Hi,
    Could anybody please let me know how to find the delivery numbers from a range of material documents based on a given delivery date.
    Regards
    Kasi

    Hi,
    there is an index table for deliveries by material:
    VLPMA
    Select the delivery numers using the material range from VLPMA.
    Regards,
    Clemens

  • How to find missing unread message in mac mail

    Hello,
    I have one unread message that I can not find, it is perhaps one of the mailchains I have. I organized my folder sort by unread and I can not find it neither. Please advise me how to find it.
    Thank you,
    Diana

    Something happened and is fixed.

  • How to find missing link in document

    Hi All,
    I require a script which can find missing links in Indesign document.
    If anybody has this script, please pass it to me.
    thanks.
    mon

    Thanks for your prompt reply.
    But it gives error "Link is read only" when I run this script.
    Please run this script and kindly let me know your comments.
    Thanks in advance.
    Mon

  • HOW TO FIND MISSING IPAD

    What are ways to find a missing or stolen ipad?

    In order for a lost iPad to be located you have to have set 'Find My iPad' up on it before losing it, and it has to be on, not wiped, and able to connect to a network (how else could it transmit its location) - if any of these conditions is not true then locating it is not possible. You can't use the serial number, or IMEI number (on iPads with a cellular connection) to locate an iPad: the former is only useful to identify it as yours if it turns up, and the latter can be used by most service providers to block it, rendering it useless and preventing anyone from spending your credit.

  • How to find missing fonts in Pages 5.0

    When I open an older document in Pages 5.0.1, the application informs me that certain fonts are missing from my system. That's helpful to know, so I can reformat the text in question to use a different font. However, I cannot seem to find *what text* has the problem. How can I locate the affected content, so that I can update the font to a valid one?
    Thank you.

    I'm away from my computer right now but I believe there is a template for that.
    Click New, select new from template, it should be there...
    Alexis

  • How to find missing files

    some files like pdf files. or files with a wrong extension are not cataloged by lightroom.
    When i start importing, a popup menu appears with files lightroom is not able to read.
    But as is said, some files are not in that list. But stil not recognized by lightroom.
    how do i now which files are in a folder. but not visible by lightroom.

    I originally had the photos organized by date folders on the hard drive, then I imported them into iPhoto.
    It sounds like you had a Referenced Library - that is, the photos were not copied to the Library on import. Now something has changed and the path to the photos has altered somehow and iPhoto cannot find them.
    iPhoto in this method uses aliases to track the location of the files. You might try repair those aliases with an app like [FileBuddy|http://www.skytag.com/filebuddy>
    If that fails there is no fast solution for this, and it's one of the reasons that I wouldn't recommend iPhoto in this configuration.
    There's also nothing to be gained from doing so.
    You can use iPhoto with Photoshop: You can set Photoshop (or any image editor) as an external editor in iPhoto. (Preferences -> General -> Edit Photo: Choose from the Drop Down Menu.) This way, when you double click a pic to edit in iPhoto it will open automatically in Photoshop or your Image Editor, and when you save it it's sent back to iPhoto automatically. This is the only way that edits made in another application will be displayed in iPhoto.
    Note that iPhoto sends a copy+ of the file to Photoshop, so when you save be sure to use the Save command, not Save As... If you use Save As then you're creating a new file and iPhoto has no way of knowing about this new file. iPhoto is preserving your original anyway.
    My best advice is to convert that Library to a Managed library.
    Regards
    TD

  • How to find missing documnets

    Hi Experts,
    My collegue says some material documents were missing oic_c03 cube.. How can i validate this?? what tcode and what search criteria shld i use to find those missing material documnet nos..
    Thanks
    DV

    Hi DVMC,
      Did you already check if the data really missing on the infocube(RSA1-Manage Infocube)? Did you already check if the data will be extracted by your datasource from R/3 (RSA3 transaction)? Did you check your update rules if there is an start routine that delete records base on a certain criteria (open update rules of infocube)? Check records on the PSA if the PSA Table contains the missing records?

Maybe you are looking for

  • How to move files from my full Time Machine to a different external drive?

    Hello there. I have a 320 GB external hard drive which I have been using as my "Time Machine." It recently filled it up and I would like to move the data (files, music, pics, etc.) to a larger external hard drive.  HOWEVER, I don't want this new driv

  • Can I really only use a CD once?

    I'm a real newbie, so bear with me. I just copied a file to a new cd then ejected it. When I put the cd back in to copy another file I got the message "The item "contacts" could not be moved because "untitled cd" cannot be modified." Can I really onl

  • How to create a new DOM tree with nodes from another DOM tree?

    Hello, I would like to create a DOM tree by using nodes from an existing DOM. How can I do that? I tried with appendChild and it gaves me as error: "WRONG_DOCUMENT_ERR". Thx!

  • What's new in Photoshop CS6 for an enthusiastic amateur?

    Is there anything in CS6 to interest an enthusiastic amateur or should I stay with my CS5.1?

  • Major Ipod (60GB VIDEO) problem

    I've just bought my first Ipod and I'm really disappointed.I installed Itunes and the ipod software,updated it and got my songs.After like 30 minutes and I don't know how and why my pod freezed in LOCK mode,I can't do anything on it,I disconnected it