Find the missing number

Hello

Oracle 11.2.0.1

Windows

SQL > select count (*) from big_table;

COUNT (*)

----------

19478769

SQL > select max (linenumber) from big_table;

MAX (LINENUMBER)

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

19478793

SQL >

I assigned a linenumber (column name) to each line.  Now I am confused which line linenumbers have troubled the order by linenumber and how do I correct linenumbers in this large table.  Let me be more specific:

create table big_table (linenumber, col1 varchar2 (10));

insert into big_table values (1, 'abc');

insert into big_table values (2, 'aaa');

insert into big_table values (4, 'xyz');

insert into big_table values (5, 'zzz');

insert into big_table values (8, 'bbb');

SQL > select count (*) from big_table;

COUNT (*)

----------

5

SQL > select max (linenumber) from big_table;

MAX (LINENUMBER)

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

8

SQL >

I need to table should have correct linenumbers as order 1,2,3,4 and 5 in linenumber.

Thank you.

something like this:

---

MERGE INTO big_table tgt
     USING (SELECT linenumber old_line_number,
                   ROW_NUMBER () OVER (PARTITION BY 1 ORDER BY linenumber)
                      new_line_number,
                   col1
              FROM big_table) src
        ON (src.ROWID = tgt.ROWID)
WHEN MATCHED
THEN
   UPDATE SET tgt.linenumber = src.new_line_number;

commit;

See you soon,.

Manik.

Tags: Database

Similar Questions

  • find the missing number of the table

    I have the vendor with the next column, refvendor_id, the refvendor_id table is a primary key in the table. the client use to enter information to the supplier table by using an interface
    created in Java. My question is how can I query the numbers of refvendor_id that have been ignored by the customer when they enter the information in the vendor table.
    refvendor_id is a varchar data type.
    for example
    
    refvenodr_id
    1
    2
    3
    5
    6
    9
    
    I would like to capture in my sql the refvendor_id that is skipped here.
    4,7,8
    
    select refvendor_id
    from  vendor

    No test! Please define: min_number to your race number:

    select rownum -1 + :min_number  from dual connect by rownum -1 + :min_number <= (select max(to_number(refvendor_id)) from refvendor where regexp_like(refvendor_id,'^[0-9]+$')  and length(refvendor_id) = 5)
    minus
    select to_number(refvendor_id) from refvendor where regexp_like(refvendor_id,'^[0-9]+$')
    order by 1;
    
  • 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

  • Please tell me where to find the registration number of contract?

    What is the registration number and where to find the registration number of contract

    If there is a link to find our registration staff den please notify

    If you can't find the number that I myself could not because I got this Macbook from my college for my future course you should give AppleCare a call as once again, I myself did. They were able to confirm the serial number on my Macbook, take my personal information, register for my Macbook, and now I'm good to go! Then call AppleCare to get the situation sorted is definitely the way to go. I waited a minute to connect, but it's easy and fast after connection with someone to AppleCare and the guy was very, very friendly and courteous. Hope this helps! Have a nice day

  • How can I find the serial number of my iPhone?

    So earlier today, I lost my iPhone 4 (it probably slipped from my pocket while I was attending). So now that I have not the device or the box, I can not find my serial number. I did not back up on my mac so I can't check for the serial number on iTunes either. I didn't find my iPhone activated so I can't take all of the measures. I plugged my iPhone on my mac several times, but not for backups, so is it possible to find my serial number on my mac?

    PS: I can not contact my local cellular provider because it is saved under my mother (I'm 14) and I don't want her to know that I lost my phone.

    Thank you in advance!

    Your parents will find out later.  You just tell them.

    Why do you think the serial number?

    It would be on the box.

    Here are the ways to find the serial number:

    You can find the serial number or IMEI on your iPhone, iPad or iPod touch...

  • How to find the serial number of the processor in the MacBook pro s serial number? I have a dead MacBook that was given for service to a third party. I doubt that they have replaced the original parts. Help, please. Thank you

    How to find the serial number of the processor in the MacBook pro s serial number? I have a dead MacBook that was given for service to a third party. I doubt that they have replaced the original parts. Help, please. Thank you

    As far as I KNOW, the serial number of the MacBook does not have the serial number of the processor.

  • Find the IMEI number

    Hello. IBought my IPhone of the Korea. I lost my Iphone 5. But I don't have the IMEI number. You can help me find my IMEI number

    iOS - how to find the serial number IMEI and MEID, CDN or ICCID number. It should also be on the box of origin in which it came. I hope you kept.

  • Where can I find the version number of the latest version of Firefox before downloading?

    I have to ask permission to download Firefox at work and he needs version number before granting approval. Texas regulators use Firefox and work does not allow microsoft to explore internet. I need Firefox to use the reports and models of agencies. The download Web site does not list the version number. Where can I find the version number of the latest version of Firefox before downloading?

    You can find the latest version of Firefox 20.0.x in all languages and for all systems operating here:

    If you put a download link, her you should see the version of Firefox in the pop-up at the bottom of the screen.

  • How to find the serial number of the Satellite M30x

    Over time, serial number has worn away from the bottom of my Toshiba Satellite M30x. is there another way that I can know what it is?

    I m not 100% sure, but maybe you can find the serial number in your document that were shipped with the laptop.

  • Satellite A200: How to find the serial number

    I need to know the ETA of my laptop so I can download the specified drivers...
    Cause when I did my search, there are several version of the SATELLITE A200...
    If anyone can help out where I can find it?

    Thank you!!

    At the bottom of the unit, you will find the label that provides all the necessary numbers.
    You will also find the serial number!

  • Where can I find the version number of the ios 9.3 update before installing?

    Where can I find the version number of an ios update before installing?

    You can not. I would like to know as well. The current building is displayed in settings > general > all. When the phone offers you an update, it does not display the new version. One could assume that it is the latest available at that time, which at present is 13E237, but to my knowledge does not appear before the update.

  • My laptop was stolen - how to find the serial number

    Hello

    Is there a way I can find the serial number of my laptop, which was stolen yesterday? I would like to save as stolen with Toshiba, but they ask the serial number.

    TNX

    Andy

    Hello

    Usually, the serial number was placed at the bottom of the unit.
    There is a label that brings together all these useful information.

    You have certainly received many documents with you laptop; is guaranteed.
    Check that and maybe you can find the serial number somewhere in the list

  • Hi, I bought Photoshop Elements editor 10 on ITunes/App store. Where can I find the serial number?

    Hi, I bought Photoshop Elements editor 10 on ITunes/App store. Where can I find the serial number?

    Where exactly did you buy it? Up to now, I know Adobe did not create a version of Photoshop Elements for iOS (iPhone, iPad, iPod Touch) devices, their iOS application is called Adobe Photoshop Express.

    If you bought it from the Mac App Store for your Mac (version 13 is the current version, 10 is interrupted), so you do not receive a serial number: https://helpx.adobe.com/photoshop-elements/kb/purchases-mac-app-store-faq.html

  • How can I find the serial number if I can't go to the back of the phone?

    How can I find the serial number if I can't go to the back of the phone?

    Two ways

    Settings - general - or about

    Connect iPhone to iTunes and to see in the summary OR section

    Sign in here

    (1211)

  • How to find the imei number of backup

    Hi, I lost my iphone. I have backup and I see on the screen of device management. I want to find the IMEI number and give information stolen from the police.

    See find the serial number and other information for your iPhone, iPad and iPod touch - Apple Support.

    TT2

Maybe you are looking for

  • How to select text in a stringcontrol

    Hi guys! Just a quick question. I received this order of string in my FP: Note that the text is selected (marked), such as when you click behind the text and made to drag your mouse over it. (Hope, je l'ai expliqué c'est bon ^ ^,)) Well, the case is,

  • Get all the rows of a table control

    Hi all I have a table with a column control. What function can I use to extract all lines? I have to go row by row and read each line or is it possible to do in a function? Thank you Kanu

  • CoH graphic glitches

    Hi, I have windows Vista 32 bit professional ed, I have service pack 1 installed and updated my video card driver and my DX 10 but in the company of heroes, there are many graphic bugs such as objects being a colored blob or see hollow of the floor a

  • Setup error 0 x 00000057 printer

    I am running windows 7 and have an Epson LQ-570 + ESC/P 2-printer-attached to a converter USB to parallel. The USB converter is recognized and the printer support appears in Device Manager, but the printer itself is not recognized.  Epson says the pr

  • Resolution error - Web fonts

    How to troubleshoot the following message appears when downloading ftp? I use self hosted web fonts﷯Error:failed to generate code to activate one or several web fonts on the 'Home' page [Error 500]