Looking for gaps (SQL, not PL/SQL)

Hi,
This is a SQL (not PL/SQL) question.
Let's say I have the following table:
COLtype          COLnumber
AA               1
AA               2
AA               4
AA               5
BB               1
BB               2
BB               3
BB               5
CC               1
CC               5
How do I find all gaps? I expect a result:
COLtype          COLnumber
AA               3
BB               4
CC               2
CC               3
CC               4
I tried to use query:
SELECT COLnumber + 1, COLtype FROM table a1
WHERE NOT EXISTS (
SELECT NULL FROM table a2
     WHERE
a1.COLtype = a2.COLtype
and (a2.COLnumber = a1.COLnumber + 1)
but I received as result:
COLtype          COLnumber
AA               3
AA               6
BB               4
BB               6
CC               2
CC               3
CC               4
CC               6
Any other solutions, ideas?
Thanks in advance!
Gaspar
Edited by: 985540 on 2013-02-01 02:59

First let define gaps. If we have:
COLtype COLnumber
AA      3
AA      4Are:
COLtype COLnumber
AA      1
AA      2missing? If so is there an assumption COLnumber always starts with 1 or we just looking for gaps between existing numbers? For now I'll assume we are looking for gaps between existing numbers. Then:
with t as (
           select  coltype,
                   colnumber,
                   lag(colnumber,1,colnumber - 1)
                     over(
                          partition by coltype
                          order by colnumber
                         ) prev_colnumber
             from  tbl
select  coltype,
        colnumber - column_value colnumber
  from  t,
        table(
              cast(
                   multiset(
                            select  level
                              from  dual
                              connect by level < colnumber - prev_colnumber
                   as sys.OdciNumberList
  where colnumber - prev_colnumber > 1
  order by coltype,
           colnumber
CO  COLNUMBER
AA          3
BB          4
CC          2
CC          3
CC          4
SQL> explain plan for
  2  with t as (
  3             select  coltype,
  4                     colnumber,
  5                     lag(colnumber,1,colnumber - 1)
  6                       over(
  7                            partition by coltype
  8                            order by colnumber
  9                           ) prev_colnumber
10               from  tbl
11            )
12  select  coltype,
13          colnumber - column_value colnumber
14    from  t,
15          table(
16                cast(
17                     multiset(
18                              select  level
19                                from  dual
20                                connect by level < colnumber - prev_colnumber
21                             )
22                     as sys.OdciNumberList
23                    )
24               )
25    where colnumber - prev_colnumber > 1
26    order by coltype,
27             colnumber
28  /
Explained.
SQL> @?\rdbms\admin\utlxpls
PLAN_TABLE_OUTPUT
Plan hash value: 1739894384
| Id  | Operation                            | Name | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT                     |      | 81680 |  2552K|       |   991   (1)| 00:00:12 |
|   1 |  SORT ORDER BY                       |      | 81680 |  2552K|  3216K|   991   (1)| 00:00:12 |
|   2 |   NESTED LOOPS                       |      | 81680 |  2552K|       |   277   (1)| 00:00:04 |
|*  3 |    VIEW                              |      |    10 |   300 |       |     4  (25)| 00:00:01 |
|   4 |     WINDOW SORT                      |      |    10 |   170 |       |     4  (25)| 00:00:01 |
|   5 |      TABLE ACCESS FULL               | TBL  |    10 |   170 |       |     3   (0)| 00:00:01 |
PLAN_TABLE_OUTPUT
|   6 |    COLLECTION ITERATOR SUBQUERY FETCH|      |  8168 | 16336 |       |    27   (0)| 00:00:01 |
|*  7 |     CONNECT BY WITHOUT FILTERING     |      |       |       |       |            |          |
|   8 |      FAST DUAL                       |      |     1 |       |       |     2   (0)| 00:00:01 |
Predicate Information (identified by operation id):
   3 - filter("COLNUMBER"-"PREV_COLNUMBER">1)
   7 - filter(LEVEL<:B1-:B2)
PLAN_TABLE_OUTPUT
Note
   - dynamic sampling used for this statement (level=2)
25 rows selected.
SQL> SY.

Similar Messages

  • Looking for a good note taking app: Are there new features for the Notes app in iOS6?

    Hi,
    I've read that the Notes app with Mountain Lion will be available for OS X as well, and I was wondering if there will be any significant updates to the Notes app coming in iOS 6?
    The Notes app in Mountain Lion supports, as far as I know, text formatting, images and attachments. The Notes app in iOS 5 does not have any of these features, yet still it is claimed that the OS X client will sync with the iPhone, iPad and iPod touch. This means that there must be some rather significant updates coming for the Notes app in iOS 6 to match up with the features of its Mac counterpart. Still, no updates to the Notes app are listed in any of the iOS 6 feature lists I've seen so far.
    I'm looking for a good note taking app for OS X and iOS. I don't like how Springpad works, neither did Evernote work out for me, it's just too complex - I like Simplenote a lot though, it's just that its approach is too radical in my opinion. I was thinking that the Mountain Lion Notes app might be a good alternative because it combines simplicity with rich text formatting and attachments. I kind of hate the skeuomorphic user interface though.
    best, Ian

    You are only addressing other iPad users here & no Apple employees. We have no way of knowing, so you'll have to wait until iOS 6 is released.
    Here's some general info.
    Working with Notes and Documents on the iPad – Alternatives & Suggestions
    http://ipadacademy.com/2012/04/working-with-notes-and-documents-on-the-ipad-alte rnatives-suggestions
     Cheers, Tom

  • Im looking for a good note app with pen for taking notes ( in english and german )during business trips. Can anyone help

    I'm looking for a good note app with pen function for taking notes ( in English and German ) during business trips. Can anyone help?

    Really sorry to hear about this, particularly when you're putting your life on the line. But Apple cannot track your iPhone in any way unless you had set up Find My iPhone prior to it being lifted.
    It's possible that AT&T might be able to do something, but it's probably that they cannot track it, or will not without a request from an authorized law enforcement agency, but rather would only disable the device. You'll have to try and find a way to contact AT&T directly and ask if they can do anything to help you; the chances of any AT&T employee in a position to help you spotting this thread it pretty small.
    Good luck, stay safe, and come home soon.
    Regards.

  • HT4400 I'm looking for a Braille note system that interacts with IPAD. This will be use in a classroom settings where you see both the braille & text communicated simultaneously.

    I'm looking for a Braille note system that interacts with IPAD. This will be use in a classroom settings where you see both the braille & text communicated simultaneously.

    This should be able to help ya out -> Support for wireless braille displays in iOS 6

  • ArrayDescriptor only SQL not PL/SQL

    ArrayDescriptor.createDescriptor only seems to work for SQL table types not PL/SQL table types. Is this true or is there some special
    syntax for naming PL/SQL table types.
    neither
    <typename>
    nor
    "<package>.<typename>"
    work
    They both raise exceptions like
    java.sql.SQLException: Fail to construct descriptor: Unable to resolve type: "NDR41.CAMLITE.TT"
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:114)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:156)
    at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:775)
    at oracle.sql.ArrayDescriptor.<init>(ArrayDescriptor.java:166)
    at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:89)
    at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:161)
    null

    Nicolas,
    This is true.
    Thanks.

  • Looking for a great note taking app on MacBook

    I'm looking for a good app for macbook pro, I used few and they all are bag or did not fit me. I want one that can record clearly and simple to use. I'm using now ''Word" it record and do the job but it look ugly I do not like using it. also for Evernote, the same thing.
    long story short I want an app that have good recording, simple to write looks like a note book or a copy book, etc, AND worth buying. Thank you :d

    You are only addressing other iPad users here & no Apple employees. We have no way of knowing, so you'll have to wait until iOS 6 is released.
    Here's some general info.
    Working with Notes and Documents on the iPad – Alternatives & Suggestions
    http://ipadacademy.com/2012/04/working-with-notes-and-documents-on-the-ipad-alte rnatives-suggestions
     Cheers, Tom

  • Looking for a small note-taking app

    I'm looking for an note-taking application that is based around the post-it note metaphor. I want to write down a lot of little notes, then rearrange them a few times. Bubbles work too.

    Not a widget, in your Applications folder.
    -mj

  • Time Machine looking for backup disk/not finding

    Time Machine backed up the HD on my 2009 20" iMac up till Feb. 4 when I downloaded Since then there have been no new backups of my HD and there have been problems wihen I have Time Machine "on" with other applications (TextEdit, Pages, Adobe Bridge CS4) opening or not responding after being open and with Finder not responding. I have also had grey screen freezes multiple times so that I have to use the power button to shut the computer down. When I take TM off of the Automatic backups, most of the problems with applications quitting and the grey screen freezes stop happening. (Although I believe I've had at least one or two grey screen freezes even then.)
    Today I've run Verify Time Machine Backups. It completed that. Then I turned on Automatic Backups again. But then it showed "Looking for Backup Disk". So I selected the Backup Disk. Then I checked back in a while and it still showed Looking for Backup Disk. I removed the selected backup disk, shut down and rebooted, and reselected the backup disk. It is still showing Looking for Backup Disk.
    The Time Machine is a 1 Terabyte size. My iMac is using 203.6 Gigabytes of its 319.21 G space.
    In looking at what my Finder is showing as the name of my Backup Disk, I see that it is showing my Backup Disk as Virginia's Computer (3). It should be showing my Backup Disk as Virginia's Computer. If this is the source of the problem, how do I get my Backup Disk named back to Virginia's Computer? Is it possible to get it changed back?
    My TM is used as a router for two iMacs and up through Feb. 4 I was sharing files between both computers. When the problems started, I turned off File Sharing in the other computer (Jim's iMac). I had noticed that frequently my computer's name as shown on the other computer would be changed to Virginia's Computer (2) or Virginia's Computer (3) and I would change it back when I noticed. Perhaps this is how the problem started.

    I finally contacted Apple Support. Three support people and seven and a half hours later Time Machine began working correctly. Multiple things were tried. The Time Capsule ended up getting erased. Many files and folders were deleted from several places on my hard drive. It seemed that the final ones that made a difference after the Time Capsule was erased were files that were in my Keychain.
    I have to thank Apple's Support people for persistence, especially Jim who is the one who got things back to normal as far as the Time Capsule & Time Machine goes. I have to keep watch to see if anything acts up now on my hard drive and then the solution will go further. But the issue with the Time Capsule and Time Machine appears to be resolved!
    Thank you, Apple Support!!!

  • Internal Time Machine "looking for backup disk" (not time capsule)

    Hello,
    I have the infamous "looking for backup disk" issue. My Time Machine drive is an internal drive, NOT a time capsule. It is mounted and visible, and the backups show up on it in the Finder. When I select to enter the Time Machine "starfield" UI, all my previous backups are browsable. But when it comes time to actually back up... it just says "looking for backup disk" forever. I've tried leaving it like that for something like 40 minutes, no joy. This is not a huge disk, there are about 700 GB of backups on it. The HDD activity light on my computer is NOT showing any activity when I am idling but it is "looking for backup disk," so I don't think it's scanning the drive or anything.
    I have tried turning TM off and on, removing the drive and re-selecting it, unmounting it and remounting it, deleting the TM preference plist file from the library, rebooting, and all manner of combinations thereof. Nothing seems to work.
    Anyone have any advice? This is on OS X 10.8.2 by the way. The TM backup worked fine through 10.8.1 and 10.8.2 with no problems until now. I don't recall doing anything specific to mess up TM or the disks in any way, although I may have turned TM during a reboot cycle prior to this happening (don't recall if this is actually the case, but in any case it shouldn't have caused such an error, no?).
    Thanks in advance,
    —Gabriel

    [Just a note, TM only works on OS X Journaled drives (i.e. HFS+ drives). TM does not back up your FAT drive.]
    Isaac:
    If you unloaded the NTFS and FAT kexts, your TM backups might (might!) work again, but of course in that case you would not be able to see your FAT or NTFS drives in OS X, and if you removed the FAT kext then a lot of USB keys would be unreadable in OS X - not a good solution.
    The kexts are specific to OS X, so removing them should not affect Windows... but may affect boot camp, I don't know how boot camp is programmed (which would be a problem). Luckily if your Windows drive became inaccessable from boot camp with removed kexts, it should be easy enough to simply boot back into OS X, restore the kexts, and then Windows should work again.
    I would recommend not mixing partition types on drives with shared OSX/Win functions, it seems to "tempt fate" as it were with possible errors. I don't know what has precipitated this error in your case, if it was the MSE or disk error or something else, and unfortunately I don't have a real fix to offer beyond trying things with the kexts removed and seeing if they work.
    NOTE THAT THIS IS AT YOUR OWN RISK, messing with kexts is not a very recommendable practice since these files enable core functionality in the OS. Make a backup before if you can, and consider your options carefully. In OS X, navigate to /System/Library/Extensions and you'll find a bunch kext files. The two you need are msdosfs.kext and ntfs.kext. Copy ntfs.kext into a backup folder (e.g., on your desktop). Delete the original ntfs.kext from the S/L/E folder. Reboot and see if you can still access windows. If so, reboot into OS X and see if Time Machine works again. If you're good on both those points, then consider going without ntfs.kext on a permanent basis – it is rare that you need to read an NTFS drive while in OS X. On the other hand, if this does not fix your problem, you may try restoring ntfs.kext, and backing up / deleting msdosfs.kext to see if THAT is the culprit. Unfortunately, if msdosfs.kext is causing the TM error, you're kind of out of luck, since going without FAT access will be pretty annoying any time you need to use a drive to swap files between Windows and Mac (using a USB key).
    Ultimately I don't have a solution, as I have noted, so much as I've narrowed down where the error is occuring in some peoples' cases (like my own). Good luck!

  • How to "where any of(b,c,d,e,f,g,h..) is null" with SQL(not PL/SQL)

    With the combinations of case, decode and coalesce function this can be done via pl/sql function, but is it possible to do it with SQL(any similar operator for this need I mean).
    This need is because this is a report and the data processed is large so if this can be done within SQL engine it may help with performance.
    Best regards.

    I don't think coalesce is what you need, but maybe I'm missing something here.
    You can use some nested nvl2 expression, but why doing it complicated. As s.rajaram says, using the or-operator will do just fine.
    SQL> create table mytable
      2  as
      3  select 1 b, 1 c, 1 d, 1 e, 1 f, 1 g, 1 h from dual union all
      4  select 1, 1, 1, 1, null, 1, 1 from dual union all
      5  select null, null, null, null, null, null, null from dual union all
      6  select 1, null, 1, null, 1, null, 1 from dual
      7  /
    Tabel is aangemaakt.
    SQL> select b, c, d, e, f, g, h
      2       , coalesce(b,c,d,e,f,g,h)
      3       , nvl2(b, nvl2(c, nvl2(d, nvl2(e, nvl2(f, nvl2(g, h, null), null), null), null), null), null) anyone_null
      4    from mytable
      5  /
    B  C  D  E  F  G  H COALESCE(B,C,D,E,F,G,H) ANYONE_NULL
    1  1  1  1  1  1  1                       1           1
    1  1  1  1     1  1                       1
    1     1     1     1                       1
    4 rijen zijn geselecteerd.
    SQL> select b, c, d, e, f, g, h
      2    from mytable
      3   where nvl2(b, nvl2(c, nvl2(d, nvl2(e, nvl2(f, nvl2(g, h, null), null), null), null), null), null) is null
      4  /
    B  C  D  E  F  G  H
    1  1  1  1     1  1
    1     1     1     1
    3 rijen zijn geselecteerd.
    SQL> select b, c, d, e, f, g, h
      2    from mytable
      3   where b is null
      4      or c is null
      5      or d is null
      6      or e is null
      7      or f is null
      8      or g is null
      9      or h is null
    10  /
    B  C  D  E  F  G  H
    1  1  1  1     1  1
    1     1     1     1
    3 rijen zijn geselecteerd.Regards,
    Rob.

  • Recovered standby database, still it is looking for gap sequence

    I have lost archive logs in both primary and standby database(deleted due to low space).
    So folloed the below steps.
    1.Identified minimum SCN from standby database.
    2.Took inremental backup from primary database according this SCN(nnnnn)
    3.Transfer this backup file to standby side
    4. Cataloged database backups and recovered the database.
    But medial recovery is searching for missing archived logs. Please advice.

    957905 wrote:
    I have lost archive logs in both primary and standby database(deleted due to low space).
    So folloed the below steps.
    1.Identified minimum SCN from standby database.
    2.Took inremental backup from primary database according this SCN(nnnnn)
    3.Transfer this backup file to standby side
    4. Cataloged database backups and recovered the database.
    But medial recovery is searching for missing archived logs. Please advice.Probably you have not restored new standby controlfile before performing recovery.

  • Looking for the release note for loan contract IDOC.

    Hi ,
         I am trying to  work with "loan contract" , I am worikng in ALE INTERFACE.I am need to use for this IDOC type " LOANSEMBA_GETDETAIL01".
    But this IDOCs are not released .
    I am working in ECC 6 version .
    I have checked with service.sap.com. But unfortunately I am not getting the proper note number for releasing this IDOC .
    Can any one help me out in this regard?
    Debasri Sarkar
    [email protected]
    [email protected]

    Hi Guys,
    Thanks for your replys!
    Best regards,
    Lee

  • SBS2011 Recovered from Missing SYSVOL and NETLOGON; looking for original cause - not restore related

    Call from client that they couldn't login to their shares. Connected to the server and found SYSVOL and NETLOGON missing. This has happened 3 times on this server 2014-01-06, 2014-03-26, and 2014-06-04. Although I have documentation and can restore quickly,
    preventing is out primary goal.
    What are the situation is which tis might happen and possible event log items that can give us a warning that this may take place.

    Searched more for SYSVOL NETLOGON Repeat. I excluded the C:\Windows\sysvol directory from Anti-virus scan to prevent locks. Links are below.Thank you,
    Jefferson Eckert
    Systems Engineer | Inline Computer & Communications
    509.783.5450 ext 158 | [email protected] | http://www.inlinecomputer.com
    Please consider the environment before printing this email
    http://blogs.technet.com/b/instan/archive/2009/07/14/what-happens-in-a-journal-wrap.aspx
    Since the PDC server was in Journal Wrap errors state and new DC was not having sysvol share avaialbe to fix the issue you need to first take the backup of sysvol and perfrom D4(authorative restore) and D2(non authorative restore) to fix the issue.http://support.microsoft.com/kb/290762/
    Also your first step should be finding why JRNL_WRAP_ERROR error has occurred. Normally, JRNL_WRAP_ERROR occurs due to drive/partition being corrupted, antivirus locking and corrupting the file during sysvol scan, heavy size of the files inside
    sysvol and netlogon shares.
    Run chkdsk in read only mode for any errors and if issue reported take the backup of server and run chkdsk/f.Exclude the sysvol/nrtds/sysvol from AV scan too.To fix the Journal wrap perfrom authorative restore assuming you have single DC.See below link too.
    what-happens-in-a-journal-:http://blogs.technet.com/b/instan/archive/2009/07/14/what-happens-in-a-journal-wrap.aspx
    Since you have restored the DC to previous state check the health of DC by running dcdiag /q and also check event log for any errors and warning and post the same if any.
    Best Regards,
    Sandesh Dubey.
    MCSE|MCSA:Messaging|MCTS|MCITP:Enterprise Adminitrator |
    My Blog
    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.
    Proposed as answer by
    VenkatSP<abbr class="affil"></abbr> Tuesday, November 20, 2012 2:02 AM

  • Looking for some DDE notes.....​..

    Hello everyone,
    Would anybody know where I could find some DDE notes? I have the labview Basic I &II, and the intermediate book, but no explanations on how to use the DDE VIs.
    Thanks a lot,
    David

    I agree. It's pretty hard to find anything on this anymore since Microsoft replaced it with ActiveX and .NET. The functions aren't even on the LabVIEW palette anymore. There is of course, the two shipping examples that send and recieve data from Excel and there are more at http://zone.ni.com/devzone/devzone.nsf/webcategori​es/B7AA6C07A04F6A708625683C000023F6. If you have a specific need, what's it for? Posting such a question to the LabVIEW forum would get you more responses.
    Message Edited by Dennis Knutson on 07-13-2005 08:39 AM

  • IPad Air cannot start cannot sync as looking for iCloud password not connecting to inernet

    Entering password means nothing as cannot connect to the interenet

    This is an iPad Air keeps asking for a iCloud password but doesn't do any good as it cannot open and connect to the internet until activated.   Would just do a complete initialization as do not know how to get there.

Maybe you are looking for

  • How to find package owning a certain file?

    Hi, I'm trying to download a source code from git and got the following error message gpg: error while loading shared libraries: libgcrypt.so.20: cannot open shared object file: No such file or directory Clearly it's not able to find the file  "libgc

  • Timestamp formula in order to have DD/MM/YYYY format for

    Hi, I would like to automate the Opportunity name with the default value as: 'OPP' + '-' + [<KeyContactLastName>] + '-' + Timestamp([<CreatedDate>]). CRM On Demand supports MM/DD/YYYY format for the field "Created: Date", but I need to have the DD/MM

  • Wirte stamt truncating in spool

    Hi I want to increase the number of characters in a line to maximum. in report stmt the line-size defined as 760. but it is truncating in the output. Ex:WRITE:/4(75) 'Number of files read ',80 variable1.    WRITE:/4(75) 'Number of files read ',80 var

  • T9 support in iOS dialer

    Hello, I'm asking me Why there's no T9 support in the dialer to get the desired contact faster. Many other mobile brands are already supporting this very useful function. Looking for a contact in the contact-list takes much longer and the favourites-

  • Pan and Zoom-I get a warning that my system does not support OpenGL

    I'm using PSE 8 on a Windows 7 64 bit system.  Whenever I view my photos in full screen mode and try to change the transitions to pan and zoom, I get a warning that my system does not support OpenGL.  I have an ATI Radeon HD 5770, updated to the late