How to identify missing records in a single-column table?

How to identify missing records in a single-column table ?
Column consists of numbers in a ordered manner but the some numbers are deleted from the table in random manner and need to identify those rows.

Something like:
WITH t AS (
           SELECT 1 ID FROM DUAL UNION ALL
           SELECT 2 ID FROM DUAL UNION ALL
           SELECT 3 ID FROM DUAL UNION ALL
           SELECT 5 ID FROM DUAL UNION ALL
           SELECT 8 ID FROM DUAL UNION ALL
           SELECT 10 ID FROM DUAL UNION ALL
           SELECT 11 ID FROM DUAL
-- end of on-the-fly data sample
SELECT  '[' || (id + 1) || ' - ' || (next_id - 1) || ']' gap
  FROM  (
         SELECT  id,
                 lead(id,1,id + 1) over(order by id) next_id
           FROM  t
  where id != next_id - 1
GAP
[4 - 4]
[6 - 7]
[9 - 9]
SQL> SY.
P.S. I assume sequence lower and upper limits are always present, otherwise query needs a little adjustment.

Similar Messages

  • How to insert multiple records in a single query

    Dear all,
    Can you please tell
    how to insert multiple records in a single query ??

    INSERT INTO table_name (column_1, column_2) VALUES ('value_A', 'value_B')OR
    INSERT INTO table_name
    (column_1, column_2)
    SELECT 'value_A', 'value_B' FROM DUAL
    UNION ALL
    SELECT 'value_C', 'value_D' FROM DUAL
    ;Edited by: Benton on Nov 9, 2010 1:59 PM

  • How to identify new records in a table using OBIEE

    Hi,
    I have price change table as and when a record comes into this table i have to generate an alert. Then show a report with the price changes on which i can invoke an action to go into my transactional system to make the chnage. And once the change is made the process again starts to look for any new price chnage records that are recieved.
    Could anyone pls tell me how to identify new records in a table.
    Rgds

    SELECT ID, LastName, FirstName,
    RANK() OVER (PARTITION BY LastName,
    FirstName ORDER BY ID) AS SeqNumber
    FROM
    (SELECT ID, LastName, FirstName
    FROM Customers
    WHERE (LastName, FirstName) IN
    (SELECT LastName, FirstName
    FROM Customers
    GROUP BY LastName, FirstName
    HAVING COUNT(*) > 1)

  • How to identify which record(s) the user hasbeen checked

    i have a internal table in which first field is represented as check box in the output .
    like bellow
      loop at g_it_final into g_wa_final.
            write : 5 sy-tabix ,
                   20 g_wa_final-g_v_check as checkbox,
                   25 g_wa_final-TRKORR,
                   40 g_wa_final-AS4TEXT.
      endloop.
    now the user will select some records from the output checking the check box
    NOW the QUESTION is
    how to identify which record(s) the user hasbeen checked(selected) ?
    so that i can disply only the selected records in the secondary list.

    Hi,
    You will have to use the 'READ LINE' command within a loop to retrieve the data back into your program.
    You may want to use the HIDE command to ease the retrieval of the checkbox value.
    Check out the online help for both of these.
    Darren

  • How to identify the trailing spaces in a column

    Hi,
    How to identify the trailing spaces in a column.
    for ex: empno char(5) and i enter 333 then there will be 2 spaces remaining. How to identify that two spaces

    One method...
    ME_XE?create table test1 (some_char char(5));
    Table created.
    Elapsed: 00:00:00.11
    ME_XE?
    ME_XE?insert into test1 values ('HI');
    1 row created.
    Elapsed: 00:00:00.07
    ME_XE?insert into test1 values ('HI HO');
    1 row created.
    Elapsed: 00:00:00.07
    ME_XE?select * from test1 where trim(some_char) <> some_char;
    SOME_CHAR
    HI
    1 row selected.
    Elapsed: 00:00:00.14
    [pre]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Converting a single column table into a two-column table

    Hi everybody
    What I'm trying to do is convert a single column table into a two-column table. Here an example:
    Table A (single column):
    ID1
    ID2
    ID3
    ID4
    ID5
    Table B (two-column) should be:
    ID1 ID2
    ID3 ID4
    ID5
    I already did it by looping through a cursor and making an insert every 2 rows, but don't like performance.
    Is there an easier/faster way to do this?
    Thanks in advance
    Oscar

    with t as (
               select 'ID1' col1 from dual union all
               select 'ID2' from dual union all
               select 'ID3' from dual union all
               select 'ID4' from dual union all
               select 'ID5' from dual
              ) -- end of sample table
    select  col1,
            col2
      from  (
             select  col1,
                     lead(col1) over(order by col1) col2,
                     row_number() over(order by col1) rn
               from  t
      where mod(rn,2) = 1
    COL COL
    ID1 ID2
    ID3 ID4
    ID5
    SQL> SY.

  • SID Generation Failed : How to identify which record in PSA

    Hello guys,
    I have a DSO where the SID Generation has failed for about 4 records due to lower case letters. I would want to fix that in PSA.
    How do I identify which record/package in PSA to change it. I have about 11,50,000 records. The DSO activation log gives you the error but doesnot give any information on which record or the key of the record.
    Is there a way to identify the packet id and the record no. in PSA which has this problem so I can fix it. Its literally impossible to find out because each package in my PSA has about 40 - 50 thousand  records.
    Any help would be rewarded.
    Thanks,
    KK

    Hi.......
    Go to the display message of the DSO activation step..........Right click display message........there it will give you which master data...........which packets......
    Also you can go to the IP monitor..........in the details tab.........there is one tab comes ODS activation........click on that...........there also you will be able to find the errorneous data packets.........
    Regards,
    Debjani........

  • How to identify database records without using rowid.

    Hello,
    I want to find a way to identify records uniquely in my database without the use of the rowid.
    What I want to do is the following :
    I have a table that contains images. Something like that :
    Table images (id number, image blob).
    Lets say that in this table I have scanned images of persons, invoices and orders.
    I want to be able to associate a record with different records from different tables from my ERP via an association table.
    this table could be :
    Table image_associations (imageid number, rowid_column varchar2(100))
    The "rowid_column" would contain the rowid of the row that is associated with the image.
    The problem is that the rowid is something that changes (for example after export/import).
    So I do not want to use rowid.
    Any ideas?
    Thanks

    What you are saying is you want to avoid theaccepted relational design theory and subvert the
    fundamental principles of very model?
    Yes !!!!Then you are very short sighted and will fail. Why would you want to do this? How is it that you think you are smarter than the forefathers of our industry? an idea so compelling that huge companies have many massive profits implementing the concepts? (sometimes even properly) and how is it that you imagine you can work outside the concepts underlying those tools, within the tool and come to a better solution? this is arrogance surely.
    >
    I think a lot of people use rowid to identify within
    plsql code a record instead of using the table-key.
    There is very limited specific application of the ROWID for temporary reference within known bounds.
    You shouldn't rely on the ROWID. Think about what it actually is: a physical location address hash.
    Don't use it. Just don't.
    As I can remember from my classrooms (a lot of years
    ago) rowid was never mentioned in ER models. Still
    that helps a lot..For very good reason. Rowid is an implementation concept, and not a logical concept.
    Oracle already makes provision at the physical storage level to store BLOBs out of line with a record. You don't need to try to do this at the logical level as I said already.

  • How to get missing records from one table

    I have one table with many records in the table. Each time a record is entered the date the record was entered is also saved in the table.
    I need a query that will find all the missing records in the table.
    so if I have in my table:
    ID          Date          Location
    1           4/1/2015        bld1
    2           4/2/2015        bld1
    3           4/4/2015        bld1
    I want to run a query like
    Select Date, Location FROM [table] WHERE (Date Between '4/1/2015' and '4/4/2015') and (Location = bld1)
    WHERE Date not in
    (Select Date, Location FROM [table])
    and the results would be:
    4/3/2015   bld1
    Thank you

    Do you have a table with all possible dates in it?  You can do a left join from that to your above mentioned table where the right side of the join is null.  If you don't have a table with all possible dates you could user a numbers table.
    Below is one way to achieve what you want with a numbers table...
    DECLARE @Table table (ID Int, DateField Date, Location VarChar(4))
    DECLARE @RunDate datetime
    SET @RunDate=GETDATE()
    IF OBJECT_ID('dbo.Numbers') IS NOT NULL 
    DROP TABLE NUMBERS
    SELECT TOP 10000 IDENTITY(int,1,1) AS Number
       into Numbers
        FROM sys.objects s1
        CROSS JOIN sys.objects s2
    ALTER TABLE Numbers ADD CONSTRAINT PK_Numbers PRIMARY KEY CLUSTERED (Number)
    INSERT INTO @Table (ID, DateField, Location)
    VALUES ('1','20150401','bld1')
    ,('1','20150402','bld1')
    ,('1','20150404','bld1');
    WITH AllDates
    as
    SELECT DATEADD(dd,N.Number,D.StartDate) as Dates
    FROM Numbers N
    cross apply (SELECT CAST('20150101' as Date) as StartDate) as D
    select * 
    from AllDates AD
    left join @Table T on AD.Dates = T.DateField
    where ad.Dates between '20150401' and '20150404'
    AND T.ID IS NULL
    LucasF

  • How to show multipe records on a single record

    Hi all,
    I have a query which can contain 1 or Many records for each S.WAS_NO or APPL_NO even. A new record is created when the APPL_STATUS changes and a timestamp is created in APPL_STATUS_CHANGE_DATE.
    select distinct
           S.APPL_ID,
           S.WAS_NO,
           S.AS_STATUS,
           S.STATUS_CHANGE_DATE,
           dense_rank() over (partition by S.WAS_NO order by S.STATUS_CHANGE_DATE) rank
      from table_a S, table b S2
    where S.APPL_ID = S2.APPL_ID
    order by S.WAS_NO, rank asc;
    Current Results:
    APPL_ID---WAS_NO---------------AS_STATUS----STATUS_CHANGE_DATE-----RANK
    6628-------E4G0YL9B08V0V6---ASSIGNED-------25/10/2011----------------------1
    6628-------E4G0YL9B08V0V6---USED--------------30/12/2011----------------------2
    Desired Results:
    APPL_ID--WAS_NO------------------AS_STATUS1----STATUS_CHANGE_DATE1----AS_STATUS2----STATUS_CHANGE_DATE2
    6628-------E4G0YL9B08V0V6----ASSIGNED---------25/10/2011------------------------USED--------------30/12/2011The rank is based on the WAS_Number and ordered by the STATUS_CHANGE_DATE so i know which order they should go in.
    I want to show 1 record per WAS_NO and show each status change with its date. There can only be a maximum of three status changes.
    I have not been able to workout how to get Multiple records onto a singe record and in different columns.
    Many thanks

    This should do what you want:
    WITH t AS
    (SELECT 6628 appl_id, 'E4G0YL9B08V0V6' was_no, 'ASSIGNED' as_status, TO_DATE('25/10/2011', 'DD/MM/YYYY') status_change_date FROM dual UNION ALL
    SELECT 6628 appl_id, 'E4G0YL9B08V0V6' was_no, 'USED' as_status, TO_DATE('30/12/2011', 'DD/MM/YYYY') status_change_date FROM dual UNION ALL
    SELECT 6628 appl_id, 'E4G0YL9B08V0V6' was_no, 'COMPLETE' as_status, TO_DATE('15/01/2012', 'DD/MM/YYYY') status_change_date FROM dual UNION ALL
    SELECT 6629 appl_id, 'A5AAFG1C07L0P2' was_no, 'ASSIGNED' as_status, TO_DATE('19/01/2012', 'DD/MM/YYYY') status_change_date FROM dual)
    SELECT   appl_id,
             was_no,
             MAX(CASE rank
             WHEN 1 THEN as_status
             ELSE NULL
             END) as_status1,
             MAX(CASE rank
             WHEN 1 THEN status_change_date
             ELSE NULL
             END) status_change_date1,
             MAX(CASE rank
             WHEN 2 THEN as_status
             ELSE NULL
             END) as_status2,
             MAX(CASE rank
             WHEN 2 THEN status_change_date
             ELSE NULL
             END) status_change_date2,
             MAX(CASE rank
             WHEN 3 THEN as_status
             ELSE NULL
             END) as_status3,
             MAX(CASE rank
             WHEN 3 THEN status_change_date
             ELSE NULL
             END) status_change_date3
    FROM    (SELECT appl_id,
                    was_no,
                    as_status,
                    status_change_date,
                    DENSE_RANK() OVER (PARTITION BY was_no ORDER BY status_change_date) rank
             FROM   t)
    GROUP BY appl_id,
             was_no

  • Reg : Joining the all internal table records into a single internal table

    Hi all
    I am having 5 internal tables and i want to put all these entries in a single intrnal table and my requirement is for each and every record it has to go through all the internal tables and if an entry is missing meand.it has to go through the other internal tables and for missing entries i should leave it as blank and rest of the contents i have to display can any please gimme some logic how to do this??
    Thanks in advance

    Don't have time or will to deliver turnkey solutions, but here is a frame:
    LOOP AT itab1...
      READ TABLE itab2 WITH TABLE KEY... (fields linking itab1 and itab2)
      READ TABLE itab3 WITH TABLE KEY... (fields linking itab1 and itab3)
      LOOP AT itab4 WHERE... (fields linking itab1 and itab4)
        READ TABLE itab5 WITH TABLE KEY... (fields linking itab4 and itab5)
        MOVE-CORRESPONDING... (all five work areas to target work area)
        APPEND itabtarget...
      ENDLOOP.
    ENDLOOP.
    so use READ when there is a 1:1 relationship (e.g. check table entry), and LOOP when there is a 1:N relationship (e.g. items for a header)
    Thomas

  • How to select a row in a single-select table view?

    Hello folks,
    I have a table view with a 'details' button. When a row is selected and 'details' is pressed, the table view disappears and a form view is displayed (like the toggle button in PCUI). I have implemented this using a navigation link. When I press 'cancel' in the form view, another navigation link takes the user back to the table view.
    My problem is, when the table view reappears, there is no row selected (the row that was selected previously, is de-selected). How do I make sure that the row remains selected?
    I tried using the collection_wrapper->mark() method in the inbound plug of the table view, but it works only for multi-select table.

    Hi Masood,
    Thanks for your reply.
    I had already tried using MARK ( iv_index = lv_index ), but it did not work because the first statement in the MARK method is
      check ME->MULTI_SELECT = ABAP_TRUE.
    Mine is a single-select table. So, using the MARK of the iterator object, with either the IV_BO or the IV_INDEX parameter also does not work. Is there any other way for a table with single row selection?
    Thanks!!!
    Rohan.

  • How to have cascading lov for a single column in tabular form

    Hi,
    How to have a cascading lov for a single column in tabular form
    ie i have one employee name column
    in tabular form if v pressed add row then one row ll be added
    In my scenario based on first row value
    the second row value to be displayed
    To achieve this what i have to do ..
    Regards,
    Pavan

    READ Cascading select list on tabular form  and
    Oracle APEX 4.0: Cascading LOVs/Select Lists | Inside Oracle APEX by Patrick Wolf BLOG
    helps you,
    Pars.

  • Is it ok? if we have 42 million records in a single fact table!!

    Hello,
    We have three outstanding fact tables, and we need to add one more fact type, and we were thinking whether we can do two different fact tables, or can we put the values in one of the same fact table which is similar, but the records are upto 42 million if we add ,so my question is having a single fact table with all records, or breaking it down, to two different ones!!!Thnx!!

    I am not sure what is an "outstanding fact" or an "fact type". A 42m fact table doesn't necessarily indicate you are doing something wrong although it does sound as odd. I would expect most facts to be small as they should have aggregated measures to speed up report. In some cases you may want to drill down to the detailed transaction level in which case you may find these large facts. But care should be taken not to allow users to query on this fact without user the "transaction ID" which obviously should be indexed and should guarantee that queries will be quick.
    Guessing from your post (as it is not clear not descriptive enough) it would seem to imply that you are adding a new dimension to your fact and that will cause the fact to increase it's row count to 42m. That probably means that you are changing the granularity of the fact. That may or may not be correct, depending on your model.

  • How to concatenate two colums into one single column

    I need some ideas to concatenate two different columns into one single column using a set of distinct values.
    For Example,
    Customer Product Number
    xyz A 1
    xyz B 2
    xyz B 1
    AAA C 7
    AAA A 1
    The result should look like this,
    Customer Value
    xyz A1 B2 B1
    AAA C7 A1
    How would I group this into once value ?
    Thanks in advance ...

    Tom's discussion of writing your own aggregate routines
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:2196162600402
    starts off with a link to the 8i alternatives
    "see
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:229614022562
    for 8i methods (not aggregates)"
    Unforutnately, it's a lot more work in 8i.
    Justin

Maybe you are looking for

  • BB10 Lack of support manual set APN

    I have bought a Z10 stl100-3 directly and not from the carrier and made sure that it should work according to the frequencies and all specs in my country (Israel) but when i want to set to my operator, the APN i can't the BB10 OS doesn't save the APN

  • Can't reboot after reinstall [solved]

    Hello everybody! this is my first post on the forum, so first of all thanks to all the devs for their work and to all the people here for their answers ( and please forgive my errors when i write in english!). This is my problem: on my laptop I have

  • Unknown error 1140

    Just got my new iPhone 5/made a purchase at the app store received msg back that an unknown device made a purchase at the app store? I confirmed it was an authroized purchase. Then the fun begins/updated my password (changed PW) on all devices/worked

  • AE error: AE_OpenGL: Failed to create OpenGL context! Turning off OpenGL. (5065 :: 0)

    Dear all, I have been reinstalling CS5 at least 10 times (without exagerating) and I keep having this error popping: AE error: AE_OpenGL: Failed to create OpenGL context! Turning off OpenGL. (5065 :: 0) Every time I save it reappears and I don't have

  • Working with topology

    Hello experts I want to check geometry gaps between polygons, lines in the present in same table and with polygons and lines present in different tables. I have built topology and loaded all geometries into topology and tried with following sql. SQL>