FInding missing sequence number

Dear All
I have a column in table like this (actually its just a sample):
TAB
MMxxxx9988
MMxxxx9990
MMxxxx9995
MMxxxx9998
MMxxxx9999
MMxxxx0000
MMxxxx0001
MMxxxx0003
MMxxxx0004
MMxxxx0005
MMxxxx0008
xxxx is variable
last four digit is a sequence number start with 0000 and end with 9999.
when the last four digit exceeds 9999 it reset to 0000
My question is : how can we find the missing sequence number for that column.
example:
for the above table , it should give the below result:
TAB
MMxxxx9989
MMxxxx9991
MMxxxx9992
MMxxxx9993
MMxxxx9994
MMxxxx9996
MMxxxx9997
MMxxxx0002
MMxxxx0006
MMxxxx0007
Thanks

One another way of doing it:
For ease of verification, I have removed the records from 0001 to 9988.
with data as
  select 'MMxxxx9988' col from dual union all
  select 'MMxxxx9990' col from dual union all
  select 'MMxxxx9995' col from dual union all
  select 'MMxxxx9998' col from dual union all
  select 'MMxxxx9999' col from dual
--  select 'MMxxxx0000' col from dual union all
--  select 'MMxxxx0001' col from dual union all
--  select 'MMxxxx0003' col from dual union all
--  select 'MMxxxx0004' col from dual union all
--  select 'MMxxxx0005' col from dual union all
--  select 'MMxxxx0008' col from dual
select distinct col, nxt_val, substr(col, 1, 6) || to_char(st_with + level, 'fm00009') miss_seq
  from (
        select col, nxt_val, col_num st_with, nxt_col_num end_with
          from (
                select col, lead(col) over (partition by substr(col, 1, 6) order by substr(col, -4, 4)) nxt_val,
                       to_number(substr(col, 7, 4)) col_num, to_number(substr(lead(col) over (partition by substr(col, 1, 6) order by substr(col, -4, 4)), 7, 4)) nxt_col_num
                  from data
         where abs(col_num - nxt_col_num) > 1
connect by level <= (end_with - st_with) - 1
   and prior col = col
   and prior sys_guid() is not null
order by col;
COL        NXT_VAL    MISS_SEQ    
MMxxxx9988 MMxxxx9990 MMxxxx09989 
MMxxxx9990 MMxxxx9995 MMxxxx09991 
MMxxxx9990 MMxxxx9995 MMxxxx09992 
MMxxxx9990 MMxxxx9995 MMxxxx09993 
MMxxxx9990 MMxxxx9995 MMxxxx09994 
MMxxxx9995 MMxxxx9998 MMxxxx09996 
MMxxxx9995 MMxxxx9998 MMxxxx09997 
7 rows selected

Similar Messages

  • Finding missed sequence numbers and rows from a fact table

    Finding missed sequence numbers and rows from a fact table
    Hi
    I am working on an OLAP date cube with the following schema:
    As you can see there is a fact transaction with two dimensions called cardNumber and Sequence. Card dimension contains about three million card numbers. 
    Sequence dimension contains a sequence number from 0 to 255. Fact transaction contains about 400 million transactions of those cards.
    Each transaction has a sequence number in 0 to 255 ranges. If sequence number of transactions of a card reaches to 255 the next transaction would get 0 as a sequence number.
    For example if a card has 1000 transactions then sequence numbers are as follows;
    Transaction 1 to transaction 256 with sequences from 0 to 255
    Transaction 257 to transaction 512 with sequences from 0 to 255
    Transaction 513 to transaction 768 with sequences from 0 to 255
    Transaction 769 to transaction 1000 with sequences from 0 to 231
    The problem is that:
    Sometimes there are several missed transactions. For example instead of sequence from 0 to 255, sequences are from 0 to 150 and then from 160 to 255. Here 10 transactions have been missed.
    How can I find all missed transactions of all cards with a MDX QUERY?
    I really appreciate for helps

    Thank you Liao
    I need to find missed numbers, In this scenario I want the query to tell the missed numbers are: 151,152,153,154,155,156,157,158,159
    Relative transactions are also missed, so I think it is impossible to get them by your MDX query
    Suppose this:
    date
    time
    sequence
    20140701
    23:22:00
    149
    20140701
    23:44:00
    150
    20140702
    8:30:00
    160
    20140702
    9:30:00
    161
    20140702
    11:30:00
    162
    20140702
    11:45:00
    163
    As you can see the sequence number of the last transaction at the 20140701 is 150
    We expecting that the first transaction of the next day should be 151 but it is 160. Those 10 transactions are totally missed and we just need to
    find missed sequence numbers

  • To find missing sequence numbers in a table

    Hi ,
    I populate the primary key column of a table using sequence which starts with 1 and increments by 1. I need to find the sequence numbers which have been skipped while inserting.

    Hi,
    Please refere the similar thread.
    Re: Identifying the missing record in a series
    Regards

  • Finding missing sequence

    Hello all.
    I'm using the Oracle 10g Database. i'm trying to figure out how to write a simple sql query to:
    find the missing numbers in a table between say 86002895 and 86005197 (inclusive)
    Ex: Current Scenario : table_1 :
    tracking_no | id_value
    86002895 | 10
    86002896 | 10
    86002899 | 10
    86002900 | 10
    86002910 | 10
    86005196 | 10
    86005197 | 10
    Expected Result1:
    " missing tracking_id " where id_value = 10 from table_1 ;
    86002897
    86002898
    86002900 to 86002910
    86002910 to 86005196
    Thanks in advance :)

    user8635888 wrote:
    Ex: Current Scenario : table_1 :
    tracking_no | id_value
    86002895 | 10
    86002896 | 10
    86002899 | 10
    86002900 | 10
    86002910 | 10
    86005196 | 10
    86005197 | 10
    Expected Result1:
    " missing tracking_id " where id_value = 10 from table_1 ;
    86002897
    86002898
    86002900 to 86002910
    86002910 to 86005196
    Thanks in advance :)Maybe something like the following:
    SQL> SELECT * FROM TEST_TAB
      2  /
    TRACKING_NO   ID_VALUE
       86002895         10
       86002896         10
       86002899         10
       86002900         10
       86002910         10
       86005196         10
       86005197         10
    7 rows selected.
    SQL> SELECT   CASE
      2              WHEN tracking_no + 1 = lead_no - 1 THEN TO_CHAR (tracking_no +1)
      3              ELSE TO_CHAR (tracking_no + 1) || '-' || TO_CHAR (lead_no - 1)
      4           END
      5              Missing_track_no
      6    FROM   (SELECT   tracking_no,
      7                     LEAD (tracking_no, 1, NULL)
      8                        OVER (ORDER BY tracking_no ASC)
      9                        lead_no
    10              FROM   test_tab
    11             WHERE   ID_VALUE = 10)
    12   WHERE   lead_no != tracking_no + 1
    13  /
    MISSING_TRACK_NO
    86002897-86002898
    86002901-86002909
    86002911-86005195
    3 rows selected.
    SQL>You can tweak the above query to match your requirement.
    Hope this helps.
    Regards,
    Jo

  • Find Missing sequence in Alphabet

    Two table records.
    (Table1) Holds values A,B,C,D,E,F....Z, AA,AB,AC,AD..e.t.c
    (Table2) Holds values A,C,D,E,F.....Z,AA,AC,AD e.t.c
    I need to compare the two tables and findout if they are in Alphabetical sequence, if any sequence is missing I need to write out to a table.
    (Table1) Has A,B,C
    (Table2) Has A,C,D So B is missing and also AB is missing.
    How do I get this accomplished in my PL/SQL

    The easiest to check whether things are missing is with the MINUS operator...
    SELECT 'in a not b', col1 FROM table_a
      MINUS
      SELECT 'in a not b', cola FROM table_b
    UNION ALL
      SELECT 'in b not a', cola FROM table_b
      MINUS
      SELECT 'in b not a', col1 FROM table_a As for whether they are in alphabetical order, the only way of guaranteeing the order of rows in a table is with an ORDER BY when we select them. Note that with an alaphabetical sort AB comes before B. But if that's not what you mean by alphabetical order help is at hand...
    SQL> create table abcd (cola varchar2(3));
    Table created.
    SQL> insert into abcd values ('A');
    1 row created.
    SQL> insert into abcd values ('B');
    1 row created.
    SQL> insert into abcd values ('C');
    1 row created.
    SQL> insert into abcd values ('AB');
    1 row created.
    SQL> insert into abcd values ('AC');
    1 row created.
    SQL> insert into abcd values ('ABC');
    1 row created.
    SQL> SELECT * FROM abcd
      2  ORDER  BY cola
      3  /
    COL
    A
    AB
    ABC
    AC
    B
    C
    6 rows selected.
    SQL> SELECT * FROM abcd
      2  ORDER  BY length(cola), cola
      3  /
    COL
    A
    B
    C
    AB
    AC
    ABC
    6 rows selected.
    SQL> Cheers, APC

  • Significance Sequence Number in PO delivery confiramtions

    significance Sequence Number in PO delivery confiramtions.
    I know its the sequence in which vendor confirms his goods to be delivered.
    But, I want to know how the number gets generated. If i go to EKES table for 1 perticular PO with delivery confirmations.
    I am not able to find the "Sequence number" in series. Number will be jumbled.. its ok...but say number 3 will be missing out of series.
    Refer to last column in below table for Sequence number.
    CC DDelivery DTimeQuantiReference Created onInb. DelItmHL IteBatch   Quantity RedM  MPN Materl C     Seq. Number                        
    ZH D11.03.2010    1,00  7008557420  14.12.2009        0  0             0,00                      1     2                                  
    AB D11.03.2010    1,00  7008557420  18.12.2009        0  0             0,00                      3     6                                  
    ZH D11.03.2010    1,00  7008557420  18.12.2009        0  0             0,00                      1     7                                  
    ZH D31.03.2010    1,00  7008557420  18.12.2009        0  0             0,00                      1     4

    Hi ,
    Could be some of the confirmations have been deleted

  • I can't find the serial number

    Because the phone was stolen. Only know ID. I want to find the sequence number
    <Personal Information Edited By Host>

    It is on your iPhone's box (that it came in).

  • SOLUTION to find Missing Frames in an Image Sequence

    Here's blog post about how to find exactly which frames are missing in an image sequence. Since AE only says that you have x number of frames missing and if your sequence is 1000s of frames it is quite tedious to try to locate them.
    http://fredross.kinja.com/find-missing-frames-in-image-sequences-511138845

    After Effects CC (12.0) has this feature built in.
    http://blogs.adobe.com/aftereffects/2013/04/whats-new-changed-after-effects-next.html

  • In standby db, can't find sequence number of Last Applied Log.

    Hello,
    Standby database is behind the primary database for over 200 hours, to repaire this, we are using a incremental backup from primary database and a restored control file.
    after starting up standby database, in Grid Control (OEM), can't find "last applied log" sequence number,
    go to that standby, do
    standby> select max(sequence#) from v$archived_log where applied='YES';
    MAX(SEQUENCE#)
    go to primary,
    do
    SQL> select max(sequence#) from v$archived_log where applied='YES';
    MAX(SEQUENCE#)
    83833
    then using OEM grid control, to Verify checks various standby database settings.
    Initializing
    Connected to instance standby_server:standby
    Starting alert log monitor...
    Updating Data Guard link on database homepage...
    Skipping verification of fast-start failover static services check.
    Data Protection Settings:
    Protection mode : Maximum Performance
    Redo Transport Mode settings:
    primary.com: ASYNC
    standby.com: ASYNC
    Checking standby redo log files.....OK
    Checking Data Guard status
    primary.com : Normal
    standby.com : Normal
    Checking inconsistent properties
    Checking agent status
    Checking applied log on standby........WARNING:
    Timed out after 60 seconds waiting for log to be applied.
    Processing completed.
    so how to fix this?
    thanks you very much.
    Edited by: 951932 on Oct 18, 2012 7:44 AM

    Hello;
    Probably nothing to fix. This is a common warning message.
    It even occurs in this example :
    http://www.databasejournal.com/features/oracle/article.php/10893_3826706_2/Oracle-11g-Data-Guard-Grid-Control-Management.htm
    Best Regards
    mseberg

  • HT1414 Hello, I have had to restore my iphone 4 to its factory setting as I had missed a number of updates and my computer was not recognising the device. I have now lost my contacts icon on the iphone and cannot find it even after syncing to my computer.

    Hello, I have had to restore my iphone 4 to its factory setting as I had missed a number of updates and my computer was not recognising the device. I have now lost my contacts icon on the iphone and cannot find it even after syncing to my computer.
    Would you know how to resolve this issue?
    Many thanks.
    Nilou

    I have now lost my contacts icon on the iphone and cannot find it even after syncing to my computer.
    Would you know how to resolve this issue?
    It's a pre-installed app and therefore cannot be deleted so you may have inadvertently moved it onto a screen or into a folder, check the utilities folder as this is a common one for it to disappear into.  Check all screens and folders and do a search in Spotlight, it will tell you if the app it still on your iPhone but unfortunately not where it is. If you find it on one or your screens or in a folder, press the icon until it wiggles and then drag it back to where you want it.  Alternatively you can reset your home screen in Settings>General>Reset>Reset Home Screen Layout.

  • HT1459 I purchase an iPod shuffle for my niece and nephew last year for Christmas.  My nephew's iPod has come up missing and I have reason to believe it was stolen.  I  used my iTunes to put music on it in the beginning can I find the serial number somewh

    I purchased an iPod shuffle for my niece and nephew last year for Christmas.  My nephew's has come up missing and I have strong reason to believe it was stolen.  Amazon cannot give me the serial number and I used my iTunes to put music on it initially.  Is there a place I can find the serial number on my iTunes and can it be tracked to different computers if someone else is using it?  My nephew no longer has the packaging.

    Type "ipod serial number" into the search bar at the top of this page by Support and read the article explaining how to find the serial number.

  • So my ipod is missing/stolen how do i find my sirreal number to locate it?

    so my ipod is missing/stolen how do i find the sirreal number to locate it?

    - If you previously turned on FIndMyiPod on the iPod in Settings>iCloud and wifi is on and connected go to iCloud: Find My iPhone, sign in and go to FIndMyiPhone. If the iPod has been restored it will never show up.
    - You can also wipe/erase the iPod and have to iPod play a sound via iCloud.
    - If not shown, then you will have to use the old fashioned way, like if you lost a wallet or purse.
    - Change the passwords for all accounts used on the iPod and report to police
    - There is no way to prevent someone from restoring the iPod (it erases it) using it.
    - Apple will do nothing without a court order                         
    Reporting a lost or stolen Apple product                              
    - iOS: How to find the serial number, IMEI, MEID, CDN, and ICCID number
    The SN will only help identify the iPod as yours if it is recovered.

  • How can find SCN or sequence number on the update operation?

    nedd to recovery database, how can find the SCN or sequence number before the update exection?
    thanks

    nedd to recovery database, how can find the SCN or
    sequence number before the update exection?Sorry - there is something confusing about your question ...
    It seems to me the SCN is the 'system change number', which identifies when a change (table, row, block, flush log buffer to log file, etc) has ocurred.
    You seem to be asking for the SCN associated with an update before the update actually occurred.
    Are you actually asking "How do I perform a point in time recovery to immediately before a specific update?"
    Perhaps you could include a few more details, such as database version. For some reason different versions have different capabilities - that could be helpful here.

  • Enq: TX - row lock contention in forms 10g sequency number generation

    Iam Getting the Deadlock issue in oracle formdeveloper 10g database is 11g Acutually in our small Hospital organization using different forms generating entrying labrequest form finally save time
    one sequency number will generated i have give procedure below every save criteria form using below procedure some time iam getting lock iam using blocksession query i have find out some
    OSUSER
    MACHINE
    TERMINAL
    PROGRAM
    SQL_ID
    LOGON_TIME
    BLOCKING_SESSION_STATUS
    BLOCKING_SESSION
    EVENT
    user423
    UMCCDOM\LEVEL4-MICU
    LEVEL4-MICU
    PrjMcr.EXE
    0ccngw7dfkmgb
    23/09/2013 11:34:41 AM
    VALID
    277
    enq: TX - row lock contention
    SYSTEM
    WORKGROUP\PRIAPPSVR
    PRIAPPSVR
    frmweb.exe
    0ccngw7dfkmgb
    23/09/2013 11:32:50 AM
    VALID
    186
    enq: TX - row lock contention
    SYSTEM
    WORKGROUP\PRIAPPSVR
    PRIAPPSVR
    frmweb.exe
    0ccngw7dfkmgb
    22/09/2013 2:49:47 PM
    VALID
    277
    enq: TX - row lock contention
    SYSTEM
    WORKGROUP\PRIAPPSVR
    PRIAPPSVR
    frmweb.exe
    0ccngw7dfkmgb
    23/09/2013 7:00:22 AM
    VALID
    186
    enq: TX - row lock contention
    user290
    UMCCDOM\LEVEL2-N
    LEVEL2-N
    PrjMcr.EXE
    0ccngw7dfkmgb
    23/09/2013 10:28:06 AM
    VALID
    277
    enq: TX - row lock contention
    lock are happen after open the code i have find out used FOR UPDATE in procedure please tell me any alternative for this every labrequest form saving time using this procedure for generating prefix sequence number multiple user using with different systems
    PROCEDURE   Gsp_GenSeqNum (I_SvPrefixCd IN VARCHAR2,I_SvUserName IN VARCHAR2,
                              O_SvSeqNum OUT VARCHAR2) IS
    --This Procedure generates the sequence number
    --by retrieving the prefix based on the code
    --supllied to the procedure.
      CURSOR  crSeqGenerator IS
             SELECT Gsn_prefix_last_num, Gsn_prefix_year
                FROM G_SEQUENCE_NUMBER
             WHERE Gsn_prefix_Cd = I_SvPrefixCd
                   AND Gsn_prefix_year = TO_CHAR(SYSDATE,'YYYY')
      FOR UPDATE OF Gsn_prefix_last_num;
      udSeqNum        G_SEQUENCE_NUMBER.Gsn_Prefix_last_num%TYPE;
      udNextSeqNum    G_SEQUENCE_NUMBER.Gsn_Prefix_last_num%TYPE;
      udYear          G_SEQUENCE_NUMBER.Gsn_Prefix_year%TYPE;
      udPrefix        G_SEQUENCE_PREFIX.Gsp_Prefix_Value%TYPE;
    BEGIN
      SELECT Gsp_Prefix_Value
      INTO udPrefix
      FROM G_SEQUENCE_PREFIX
      WHERE Gsp_Prefix_Cd = I_SvPrefixCd;
      OPEN crSeqGenerator;
      FETCH crSeqGenerator
       INTO udSeqNum,
            udYear;
      IF crSeqGenerator%FOUND THEN
         udNextSeqNum  :=udSeqNum + 1;
         O_SvSeqNum     := udPrefix||'/'||TO_CHAR(SYSDATE,'YY')
                                   ||'/'||LPAD(TO_CHAR(udNextSeqNum),6,'0');
      ELSE
    INSERT INTO G_SEQUENCE_NUMBER VALUES(I_SvPrefixCd,TO_CHAR(SYSDATE,'YYYY'),0,I_SvUserName,SYSDATE);
         udSeqNum      :=0;
         udNextSeqNum  :=udSeqNum + 1;
         O_SvSeqNum:=UdPrefix||'/'||TO_CHAR(SYSDATE,'YY')
                             ||'/'||LPAD(TO_CHAR(udNextSeqNum),6,'0');
      END IF;
      UPDATE G_SEQUENCE_NUMBER
         SET Gsn_Prefix_last_num=udNextSeqNum
       WHERE Gsn_Prefix_Cd = I_SvPrefixCd
         AND Gsn_Prefix_year=TO_CHAR(SYSDATE,'YYYY');
      CLOSE crSeqGenerator;
    END Gsp_GenSeqNum;
    Thanks
    subbu

    This application is inbuit with some modules VB (cath ,cardio)and oracle forms for required sequence number generation different time used this procedure whereever required the sequence Prefix generation.If i replace the procedure sequene to oracle standard sequency if the user cannot save the form unnessary sequency generated order is missing from sequence.

  • "Open VI Reference" Option "Prompt user to find missing subVIs"

    I am using "Open VI Reference" to dynamically load a VI. For the "option" control of the "Open VI Reference" node, I pass "0x10" or "10" in hexadecimal, which supposedly "prompt user to find missing subVIs." Nevertheless, I don't get a prompt message dialog when I intentionally pass an invalid or missing VI path. Instead I just get an Error Code 7. What does this option "Prompt user..." suppose to do?

    Make sure you set the properties on the integer input into the “options” control to the “Open VI Reference” to be a Hexadecimal format (right-click on the “options” control input, select Format and Precision…, then select Hexadecimal). Now, if you re-run your VI and wire in a VI with a missing subVI, the Open VI Reference will appear with a dialog that will prompt you to browse to the missing subVI. This is exactly the same message LabVIEW displays when it attempts to open a VI and cannot find its subVIs.
    I’ve attached a simple example program to demonstrate. Enter the path to the “number extractor.vi” as the VI to open. You should see a dialog prompt appear asking for the “Search 1D Array – Complete.vi”.
    Hope this helps!
    Attachments:
    openVIRefExample.zip ‏20 KB

Maybe you are looking for