Find the missing numbers

I want to find the missing of a column that is alphanumeric numbers, its last five positions are digital. In the first three places there are different combinations of alphas that is * 'BA', 'BAW","SA","SAA"... * If alphas are two then 3rd position is empty. I also need to generalize this to cover all digital series existing alpha.
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 get the error ORA-01722

You have two problems with this task.

1 problem is how to convert a number from the back so that you can compare the values.

to_number(SUBSTR (b.claim_no, 4, 5)) 

works, but only if the b.claim_no value is always a number regardless of the other criteria of the column.

Such an assertion

...
WHERE SUBSTR (a.claim_no, 1, 3) = 'BA ' /* filter 1 */
and to_number(SUBSTR (b.claim_no, 4, 5)) > 1 /* filter 2 */
...

may fail because your table can have value as

b.claimno = "XYZ1234b".

The way you wrote the query of the database will decide what filter criteria, it first runs. It could be filter1, but could also be filter2. If filter2 is executed first, you will get the error message.

Problem 2 how to order and compare different lines, so that you can find the missing values.

Here the analytical function of the LEAD (LAG) is very useful. It gives you access to the next (or previous row).

Both problems can be overcome.

Here is my test, but I don't know if it works in your case. You may have to adapt a little.
This should work if all lines are digital which belong to specific groups. If you have too much data incorrect in there, then a different approach is necessary.

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       11113

1 problem is solved because where condition is always executed before the function in the select clause, in particular in the context of an analytic function.
Problem 2 is also solved by using the analytical function, function LEAD. And it's fast, because you access the same table only once. Another solution could be a subquery to extract the value of the next line. This means that multiple access to the same table and is usually much slower.

Published by: W. Sven 20 Sep, 2010 14:32

Tags: Database

Similar Questions

  • Find the missing numbers in a sequence

    Hello

    We have an ORDH table, which is having an ORDERNO field which starts from 300000. currently there are approximately 100 000 documents exist in this table.
    The ORDERNO value is generated from a sequence.
    We want to find missing persons (hole in the sequence) ORDERNO from the ORDH table.
    (Ex: 300654 is missing and there are many others also missing order numbers)
    Is it possible to find all the numbers missing command in this table?

    Thanks and greetings
    Murali

    Hi, Murali,

    This will show you the missing channels in numbers between existing numbers:

    WITH     got_next_orderno     AS
    (
         SELECT     orderno
         ,     LEAD (orderno) OVER (ORDER BY orderno)     AS next_orderno
         FROM     ordh
    )
    SELECT     ordrno + 1          AS from_no
    ,     next_orderno - 1     AS to_no
    FROM     got_next_orderno
    WHERE     orderno     + 1     != next_orderno
    ;
    

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and INSERT statements) and the results desired from these data.

  • I'm unable to find the missing drivers on my device manager.

    OT: Re: lack of pilots.

    Hello

    I'm unable to find the missing drivers on my device manager. A unknown device watch. Other shows, like in the storage controllers. I checked Windows update, but it does not find the missing drivers. I don't have the drivers on my CD.

    Please download and run the display driver and download a copy of the report he produced on your OneDrive. To obtain a report all drivers Select Edition, select all followed by file, save selected items.
    http://www.NirSoft.NET/utils/DriverView.html

    Please provide a copy of your system information file. Type the system information in the search box above the Start button and press the ENTER key (alternative is select Start, all programs, accessories, System Tools, system information). Select file, Export and give the file a name noting where it is located. Not to place the cursor in the body of the report before exporting the file. The system creates a new information file system each time system information is available. You must allow a minute or two before the file is completely filled before exporting a copy. Please download the file to your OneDrive, to share with everyone and post a link here. Normal mode preferred report. Please say if the report was obtained in safe mode. The request for a copy of this file is additional to answer the question about the brand and the model. If the report is in one language other than English, please indicate the language.

    For assistance OneDrive see paragraph 9.3

    http://www.gerryscomputertips.co.UK/MicrosoftCommunity1.htm

  • Find the missing series or page n

    I have a table

    document_sl_no, from_page, book_no, to_page

    1                              1          1               9

    2                              1          10             12

    3                              1          18              33

    Documents binded in the books and the Livre_No is entered in the database, so that if we find the hard copy of the document we can search easily.

    I need to write a query that miss me page in the pagination sequence book will give.

    as in the above example page No 13,14,15,16,17 are missing.

    Y at - it no way out.

    I was tring to get the sequence first then thought to find the missing sequence using advance or delay.

    So any suggestions to get the sequence of this wise Livre_No table

    Livre_No page_no

    11
    12
    13
    14
    15
    16
    17
    18
    19
    110
    111
    112
    118
    119
    120
    121
    122

    Something like this:

    books (book_no, from_page, to_page) as)
    Select 1,1,9 from all the double union
    Select 1,10,12 from all the double union
    Select double 1,18,33
    )
    run like)
    Select
    Livre_No
    from_page
    to_page
    , (from_page, 1, to_page) ahead of (Livre_No order of from_page partition)
    -to_page diff
    books
    )

    Select
    Livre_No
    from_page
    to_page
    , case when diff > 2 then
    diff-1 | "the missing pages after" | to_page
    lack of end
    leaks

    BOOK_NO FROM_PAGE TO_PAGE MISSING
    1 1 9 -
    1 10 12 5 missing pages after 12
    1 18 33 -
  • I can't find the serial numbers for my CS3 and Photoshop CS5 on the page my Adobe products. I registered these past two years

    I can't find the serial numbers for my CS3 and Photoshop CS5 on the page my Adobe products. I registered these past two years. Kenneth Robison

    Contact adobe support by clicking on this link then "still need help" as soon as it appears, https://helpx.adobe.com/contact.html

  • How can I find the missing e-mails Outlook Express6

    All messages in the Inbox disappears from 13/04.I I receive all messages from 14/04.Please someone help me find my old emails.

    Just to elaborate on the correct assessment of Steve.

    Two reasons the most common for what you describe is disruption of the compacting process, (never touch anything until it's finished), or bloated folders. More about that below.

    Why OE insists on compacting folders when I close it? :
    http://www.insideoe.com/FAQs/why.htm#compact
     
    Why mail disappears:
    http://www.insideoe.com/problems/bugs.htm#mailgone
     
    About file Corruption:
    http://www.Microsoft.com/Windows/IE/community/columns/filecorruption.mspx

    Recovery methods:

    If you use XP/SP2 or SP3, and are fully patched, then you should have a backup of your dbx files in the Recycle Bin (or possibly the message store), copied as bak files.

    To restore a folder bak on the message store folder, first find the location of the message store.

    Tools | Options | Maintenance | Store folder will reveal the location of your Outlook Express files. Note the location and navigate on it in Explorer Windows or, copy and paste in start | Run.

    In Windows XP, the .dbx files are by default marked as hidden. To view these files in the Solution Explorer, you must enable Show hidden files and folders under start | Control Panel | Folder options | View.

    Close OE and in Windows Explorer, click on the dbx to the file missing or empty file, then drag it to the desktop. It can be deleted later once you have successfully restored the bak file. Minimize the message store.

    Open OE and, if the folder is missing, create a folder with the * exact * same name as the bak file you want to restore but without the .bak. For example: If the file is Saved.bak, the new folder should be named saved. Open the new folder, and then close OE. If the folder is there, but just empty, continue to the next step.

    First of all, check if there is a bak file already in the message. If there is, and you have removed the dbx file, go ahead and rename it in dbx.

    If it is not already in the message, open the trash and do a right-click on the file bak for the folder in question and click on restore. Open the message store up and replace the .bak by .dbx file extension. Close the message store and open OE. Messages must be in the folder.

    If messages are restored successfully, you can go ahead and delete the old dbx file that you moved to the desktop.
     
    If you have not then bak copies of your dbx files in the Recycle Bin:

    DBXpress run in extract disc Mode is the best chance to recover messages:
    http://www.oehelp.com/DBXpress/default.aspx

    And see:
    http://www.oehelp.com/OETips.aspx#4

    A general warning to help avoid this in the future:

    Do not archive mail in default OE folders. They finally are damaged. Create your own folders defined by the user for mail storage and move your mail to them. Empty the deleted items folder regularly. Keep user created folders under 300 MB, and also empty as is possible to default folders.

    Disable analysis in your e-mail anti-virus program. It is a redundant layer of protection that devours the CPUs, slows down sending and receiving and causes a multitude of problems such as time-outs, account setting changes and has even been responsible for the loss of messages. Your up-to-date A / V program will continue to protect you sufficiently. For more information, see:
    http://www.oehelp.com/OETips.aspx#3

    And backup often.

    Outlook Express Quick Backup (OEQB Freeware)
    http://www.oehelp.com/OEBackup/default.aspx

  • two of my sent files are missing from windows mail, and I am unable to trace it? Please let me know how to find the missing folder

    Until a few days back all sent files has been noticed but suddenly two of the sent files are missing and I am unable to find the same.  I use vista and windows mail.  Please let me know how recover/find missing files.

    Thank you
    Mahesh

    Try searching *.eml and make sure you include hidden files and folders in the search parameters.  See also here for the Organization of store message (www.oehelp.com/backup.aspx#wm).  You should be able to use the browser to go to the directory of sent items under the directory of local records and the actual messages will be located there.  It may be useful to compact and repair the database (see www.oehelp.com/WMUTil/) and make sure that everything in the folder, you saw the value. Current view | Show all messages.

    Steve

  • How to find the 'missing' images easily in LR 3?

    In the beginning (I'm a technoidiot), I made some mistakes and stored images in 3 places.  To try to consolidate, I moved files and now some of the images "be found" by LR.  I am currently looking looking up the number of the image one at a time.

    In the library module, look at the on the left side.

    See all "missing files"?

    If so, just find the file to LR and all images of thhe in this folder will be re-found, too.

    If you don't have missing files and you need images, then you can always follow these steps:

    Right-click on the folder (in Control Panel folder) and click on "synchronize the folder. LR then check the file and images that are not in the record of exit and re - import those that you put in this folder.

    You can also do this with your parent folder and Sub folders will be synchronized.

    And don't forget: If you want to move pictures or folders around, always do go in LR (drag / move). This way above any change syou stay LR will do.

    WW

  • Where can I find the version numbers more up-to-date applications?

    I'm looking for a place that simply shows the version numbers more recent applications, that it becomes difficult to understand.

    You are looking for something like this in a list that is updated:

    • Adobe Photoshop
      • last: 2015.5
    • Adobe Premiere
      • last: 2015.3
    • ........

    It sounds like something, adobe would have listed publicly somewhere.   If they don't, it would be something to be considered as a useful tool for users.

    You can check the latest version of update at the bottom of the link, it is indexed properly as well as version numbers:

    2015 all updates of Adobe CC: Direct for Windows download links | ProDesignTools

  • Find the missing documents and insert accordingly

    Oracle version: Oracle Database 11g Express Edition Release 11.2.0.2.0 - Production

    Hello gurus

    I'm really grateful if someone would help out me. Thanks in advance

    Examples of data

    Drop, the creating and inserting in tables

    drop table TYPE_MST;
    drop table TYPE_VERSION;

    -------------------------
    Create Tables:

    create the table TYPE_MST
    (
    Type_desc varchar2 (15)
    );

    -----------------

    Table insert

    insert into TYPE_MST
    (
    Select 'First' double
    Union of all the
    Select 'Second' double
    Union of all the
    Select 'Third' double
    );

    --------
    create the table TYPE_VERSION
    (
    TYPE_DESC varchar2 (15).
    MIN_AGE number (5),
    MAX_AGE number (5),
    VERSION_ID number (5)
    );
    ---------
    insert into TYPE_VERSION
    (
    Select 'First', 0, 5, 100 double
    Union of all the
    Select 'First', 5, 10, 100 double
    Union of all the
    Select 'First', 11,15, 100 double
    );

    ---------

    Queries against existing data
    Select * from TYPE_VERSION;

    The query result

    TYPE_DESC, MIN_AGE, MAX_AGE, VERSION_ID

    First                      0                5               100

    First                      5                10             100

    First                      11              15             100

    My requirement is that system automatically inserts type_desc missing in TYPE_VERSION.

    For example, we have 3 Type_Desc, first, second, third, but in the TYPE_VERSION table, we have data available for only 1 Type_Desc who is "First", this system should insert the missing data in this table using existing data.

    I need result something like below:

    Required result

    TYPE_DESC, MIN_AGE, MAX_AGE, VERSION_ID

    First                      0                5               100

    First                      5                10             100

    First                      11              15             100

    Second 11 15 100

    Second                   5                10             100

    Second 11 15 100

    Third                    0                5               100

    Third                     5                10             100

    Third 11 15 100

    Thanks in advance

    Concerning

    Shu

    Hello

    It is still not clear what you want.

    That's what you want for the examples you gave:

    MERGE INTO dst type_version

    WITH THE HELP OF)

    SELECT DISTINCT

    m.type_desc

    v.min_age, v.max_age, v.version_id

    OF type_mst m

    CROSS JOIN type_version v

    )                  src

    WE (dst.type_desc = src.type_desc

    AND dst.min_age = SRC. MIN_AGE

    )

    WHEN NOT MATCHED THEN INSERT

    (dst.min_age, dst.max_age, dst.type_desc, dst.version_id)

    VALUES (src.min_age, src.max_age, src.type_desc, src.version_id)

    ;

    If she's going to do what you want in general depends on what you want in general.  As long as I don't know the General rules you want to set up, I don't know if it makes them or not.

    This does not seem a very good design.  Why do you need a table with all possible combinations?  Sounds like you're saying, for example, if 2 lines have the same value of min_age, then have the same values for max_age and version_id, too.  This 3rd Normal violares form.  Why not have a table with the possible values for min_age max_age version_id, and simply join cross which type_mst when you need to see all possible combinations?

  • Outer join to find the missing?

    I have 2 tables:

    with stud_courses as
    (
    Select studentid 111, 2, 2201 coursecategory courseid, 'A' GRADE of double
    Union
    Select studentid 111, 2, 2203 coursecategory courseid, CATEGORY "B" of the double
    Union
    Select studentid 111, 4 coursecategory, 2121 courseid, 'A' GRADE of double
    Union
    Select studentid 222, 3 coursecategory, 1111 courseid, 'A' GRADE of double
    Union
    Select studentid 222, 3 coursecategory, 1112 courseid, 'A' GRADE of double
    )
    course_categories as
    (
    Select 2 coursecategory, 2201 courseid double
    Union
    Select 2 coursecategory, 2202 courseid double
    Union
    Select 2 coursecategory, 2203 courseid double
    Union
    Select 2 coursecategory, 2204 courseid double
    Union
    Select 3, 1110 coursecategory courseid double
    Union
    Select 3 coursecategory, 1111 courseid double
    Union
    Select 3 coursecategory, 1112 courseid double
    Union
    Select 3 coursecategory, 1113 courseid double
    Union
    Select 4 coursecategory, 2120 courseid double
    Union
    Select 4 coursecategory, 2121 courseid double
    Union
    Select 4 coursecategory, 2122 courseid double
    Union
    Select 4 coursecategory, 2123 courseid double
    )

    For each student, wants to add the missing courseids for the coursecategory he takes. So student because 111 is in coursecategory 2 I should be able to show all results for him, including the ID of course 2202 and 2204 of category 2 and 2120, 2122, 2123 for this child

    My end result would be something like:

    StudentID, courseid, coursecategory, grade
    111,2,2201, "A".
    111,2,2201, '
    111,2,2203, 'B '.
    111,2,2201, '
    111,4,2120, '
    111,4,2121, "A".
    111,4,2122, '
    111,4,2123, '
    222,3,1110, '
    222,3,1111, "A".
    222,3,1112, "A".
    222,3,1113, '

    I know how to do it with a Union and not exists, but I was wondering if I could do it with an outer join.

    I would appreciate your help.

    Thank you

    Hello

    Yes, you can do it with an outer join. The tricky thing is you need outside to join the table real stud_courses to something that has valid all combinations of the studnents and prices. There is no single table that contains it; the following query will receive these combinations by making a cross join:

    WITH     all_students     AS
    (
         SELECT DISTINCT     studentid
         FROM          stud_courses
    )
    ,     got_category_cnt     AS
    (
         SELECT     all_s.studentid
         ,     c.coursecategory
         ,     c.courseid
         ,     NVL ( s.grade
                  , 'M'
                  )               AS grade
         ,     COUNT (s.grade) OVER ( PARTITION BY  all_s.studentid
                                     ,          c.coursecategory
                             )      AS category_cnt
         FROM           all_students         all_s
         CROSS JOIN      course_categories  c
         LEFT OUTER JOIN      stud_courses         s  ON    s.studentid     = all_s.studentid
                                             AND   s.courseid          = c.courseid
    )
    SELECT       studentid
    ,       coursecategory
    ,       courseid
    ,       grade
    FROM       got_category_cnt
    WHERE       category_cnt     > 0
    ORDER BY  studentid
    ,       coursecategory
    ,       courseid
    ,       grade
    ;
    

    The results I get are:

    `STUDENTID COURSECATEGORY   COURSEID G
    ---------- -------------- ---------- -
           111              2       2201 A
           111              2       2202 M
           111              2       2203 B
           111              2       2204 M
           111              4       2120 M
           111              4       2121 A
           111              4       2122 M
           111              4       2123 M
           222              3       1110 M
           222              3       1111 A
           222              3       1112 A
           222              3       1113 M
    

    These are a little different from what you have posted.

    user9207291 wrote:
    ...
    StudentID, courseid, coursecategory, grade
    111,2,2201, "A".
    111,2,2201, '
    111,2,2203, 'B '.
    111,2,2201, '
    111,4,2120, '
    111,4,2121, "A".
    111,4,2122, '
    111,4,2123, '
    222,3,1110, '
    222,3,1111, "A".
    222,3,1112, "A".
    222,3,1113, '

    Is it because there are errors in what you posted? Do you really want to have three lines of output for the same studentid (111) and courseid (2201)?

    Looks like there should be a slick way to do this with a partitioned outer join.
    A partitioned outer join matches each row of table A with the lines in table B, but, if there is no correspondence between a given A line and a line to a given partition of B, that the rank of A and the B partition is included in the game anyway. Here, we want the two partition tables.

  • How can I find the phone numbers called from this phone?

    How can I find phone numbers of this Iphone 6?

    If you open the phone application, the list of recent calls recent 100 facts/on calls the device, with the exception of the deletions which can be done on the device. If the list is empty, then the phone has not made/received all calls or the list has been removed.

  • where to find the missing files .lsb

    Hello. Here's my problem, maybe you can advice me well.

    I have an old .vi in Labview 4.0, which works very well under Windows 98.

    My final goal is to make it work under Windows 7, Labview 2010.

    I know that the first, I have to open the vi in BT 8.0, except for previous version 8.0 and then open it in LV 2010.  Generally, these tasks work correctly with the other vi. I had good results with the other vi.

    But for my situation, this old vi Labview 4.0 needs some libraries (.lsb files) CIN. It gives me errors because of them.

    Here it is:

    ICTRCTRL.lsb

    DIGPRTRD.lsb

    DIGPRTCF.lsb

    AICTRL.lsb

    CHLINDVI.lsb

    AITRIG.lsb

    AICLKCFG.lsb

    AIBUFFCF.lsb

    AIHARD.lsb

    AIGRPCFG.lsb

    AIREAD.lsb

    I tried these files in Labview 4.0 and 8.0 without success. I think that copy and paste will help as I did with the other missing Subvi.

    So my question is: how to find them and 'export' in Labview 8.0?

    Is it possible to find it elsewhere on the web? Or maybe you have?

    You know that I have no experience working with external libraries.

    The only way you can have old screw DAQ with a CIN is if these screws were saved in a Bachelor's degree in law. To avoid that LabVIEW loading them, they must be removed from the llb. So, if you install the latest version of traditional DAQ, which will load and the latest LabVIEW don't use RISC. You will then have to rewrite the program to use DAQmx features since it is the only rider with the support of windows 7.

  • How to find the missing file ' accserv. MIB'

    I tried to dwnld components from a cd, I was not able to file "accserv.mib is not found. How can I find file, or I can reinstall it.

    Hi Ms. Bestes,
     
     
    Given the name of file, I am assuming you are using XP (and it will be moved here).  If this isn't the case, please post to the system recovery and the theme of the repair in the Windows Forum appropriate to your operating system.

    Go to start / all programs / accessories / command prompt.  Type sfc/scannow and enter, preferably with your installation disc in the CD drive, which should find and fix the file, if it is actually absent.

    Another option, a little more extreme, but also more likely to work, is to try a 'repair installation' using the actual installation disc.  See: http://michaelstevenstech.com/XPrepairinstall.htm.

    I hope this helps.

    Good luck!

    P. S.

    On the computer itself:

    It must usually be or can be found here: C:\Windows\System32\accserv.mib

    It can sometimes be found here if it is not there (or even if it is there): C:\Windows\ServicePackFiles\i386\accserv.mib

  • I am running Windows XP Home Edition. Recently, I was unable to boot my computer. Get always error message__ "Missing kernel file, insert the startup disk and restart" __How can I fix/find the missing file

    Core leader Missing, insert boot disk and restart

    amerirish50,

    Demarrer start from your XP CD in Recovery Console, and then run the following command

    sfc/scannow (you will need an XP CD for this command)

    If that is not correct the problem, then you can try to perform a repair installation.

    Windows XP installation options

    Mike - Engineer Support Microsoft Answers
    Visit our Microsoft answers feedback Forum and let us know what you think.

Maybe you are looking for

  • What is the name of the address file, and where is he?

    I would like to import it into gmail

  • Question of updating the BIOS for Qosmio F50 - 10 k

    Hiya: + This Bios update adds functionality to your system. ++ (BIOS stands for Basic Input and Output System. This program is stored in a chip memory dead on the motherboard. +"+ When the computer turns on, the BIOS is launched to perform various fu

  • A pilot missing for HP EliteBook Folio 9480 m / unknown Devide driver is missing

    Hello On my HP EliteBook Folio 9480 m Windows 7 Ultimate x 64 I have installed all the drivers on the HP.com site but a driver is still missing and on Device Manager it says device UNKNOWN?Should which driver I install to make sure that this driver i

  • why I get buzzing on my headphones

    I have windows vista 32 bit and I get the buzz on my headphones, or when I play music. (any music from WMP or Youtube, as well as just randomly get buzzing. I plugged my speaker jack in another outlet and still the same problem. I tried also also put

  • Problems with ports ethernet E4200

    I have problems with my ethernet ports on my router E4200 V1.  I do not get on flow rate of 12 Mbps on a single connected wired computer.  If I replace it with a simple switch 5 port I get 60 Mbit/s using the same cables.  I looked through the creati