Getting maximum length with the same pattern from a group of string

I have a table of two columns. This table has 10 rows like this:
col1      col2
g1        abcdef
g1        abcdef-1
g1        abcdef-2-ghi
g1        abcde
g2        abc
g2        abcdefghijklmn
g2        abcdef
g2        acbdef
g2        abc
g2        abWhat I want is a query that will produce resultset like shown below
col1      col2
g1        abcde
g2        afor group g1 the result is abcde because that's the longest consecutive sequence of same characters (scanned from left to right) from all the strings that's grouped under g1. the same applies for g2. Anybody help? thanks.
Edited by: user9080476 on May 26, 2011 11:42 PM

Here's another complex solution. This one uses bit manipulation.
I'm not sure if it always works with non-ascii characters... too tired to check right now
WITH t AS (SELECT 'g1' AS col1, 'abcdef' AS col2 FROM DUAL
           UNION  ALL
           SELECT 'g1', 'abcdef-1' FROM DUAL
           UNION ALL
           SELECT 'g1', 'abcdef-2-ghi' FROM DUAL
           UNION ALL
           SELECT 'g1', 'abcde' FROM DUAL
           UNION  ALL
           SELECT 'g2', 'abc' FROM DUAL
           UNION  ALL
           SELECT 'g2', 'abcdefghijklmn' FROM DUAL
           UNION  ALL
           SELECT 'g2', 'abcdef' FROM DUAL
           UNION ALL
           SELECT 'g2', 'acbdef' FROM DUAL
           UNION  ALL
           SELECT 'g2', 'abc' FROM DUAL
           UNION  ALL
           SELECT 'g2', 'ab' FROM DUAL
           UNION  ALL
           /* some non-ASCII chars, just to make it more interesting... */
           SELECT 'g3', 'the quick brown fox òx€€' FROM DUAL
           UNION  ALL
           SELECT 'g3', 'the quick brown fox òx€ùè' FROM DUAL
           UNION ALL
           SELECT 'g3', 'the quick brown fox òx€à' FROM DUAL
           UNION ALL
           SELECT 'g4', null FROM DUAL
           UNION  ALL
           SELECT 'g4', 'the quick brown fox òx€ùè' FROM DUAL
           UNION ALL
           SELECT 'g4', 'the quick brown fox òx€à' FROM DUAL
           UNION  ALL
           SELECT 'g5', '€' FROM DUAL
           UNION ALL
           SELECT 'g5', '€' FROM DUAL
           UNION  ALL
           SELECT 'g6', 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzA' FROM DUAL
           UNION ALL
           SELECT 'g6', 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzABC' FROM DUAL
     t2 as (
             select
             t.*,
             rpad(col2,max(length(t.col2)) over(partition by t.col1)) as col2_pad from t
     t3 as (
           select
           t.col1,
           t.col2,
           utl_raw.bit_xor(utl_raw.cast_to_raw(t.col2_pad),
                      utl_raw.cast_to_raw(lag(t.col2_pad) over(partition by col1 order by col2))) as col2_xor from t2 t
            select
            distinct
            t.col1,
            -- t.col2,
            substrb(t.col2,1,
            floor(
            least(
               min(case when t.col2 is null then 0 else lengthb(t.col2) end) over(partition by t.col1) * 2,
            min(case when t.col2_xor is null then 9999999999999999
                      else regexp_instr(rtrim(t.col2_xor,'0'),'[1-9A-F]') end)
                           over (partition by t.col1) - 1)
            /2)
             from t3  t        
           order by 1,2

Similar Messages

  • How to get  data with the raw pattern from resultset ?

    would you tell me how to get data with the raw pattern from resultset ?
    thank you in advance!
    longgger2000

    I tried getBytes() and getObject()
    , but I can not get the right result , for example the
    data in oracle database is 01000000DFFF, when In used
    the method of getBytes() and getObject(), I get the
    result of [B@1c2e8a4, very different , please tell me
    why !
    thank you
    longgger2000
    [B is byte arrayseem that it return an bytes array for you.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • I use 2 to 3 computers for my photo retouching, can I get them activated with the same serial number? for Photoshop Elements 13, and premier elements 13

    I use 2 to 3 computers for my photo retouching, can I get them activated with the same serial number? for Photoshop Elements 13, and premier elements 13

    You can activate any two of them at a time, but if you want to use it on a third computer you will need to deactivate one of them before you can do so. To do that, go to Help>Sign Out.

  • How do I call methods with the same name from different classes

    I have a user class which needs to make calls to methods with the same name but to ojects of a different type.
    My User class will create an object of type MyDAO or of type RemoteDAO.
    The RemoteDAO class is simply a wrapper class around a MyDAO object type to allow a MyDAO object to be accessed remotely. Note the interface MyInterface which MyDAO must implement cannot throw RemoteExceptions.
    Problem is I have ended up with 2 identical User classes which only differ in the type of object they make calls to, method names and functionality are identical.
    Is there any way I can get around this problem?
    Thanks ... J
    My classes are defined as followes
    interface MyInterface{
         //Does not and CANNOT declare to throw any exceptions
        public String sayHello();
    class MyDAO implements MyInterface{
       public String sayHello(){
              return ("Hello from DAO");
    interface RemoteDAO extends java.rmi.Remote{
         public String sayHello() throws java.rmi.RemoteException;
    class RemoteDAOImpl extends UnicastRemoteObject implements RemoteDAO{
         MyDAO dao = new MyDAO();
        public String sayHello() throws java.rmi.RemoteException{
              return dao.sayHello();
    class User{
       //MyDAO dao = new MyDAO();
       //OR
       RemoteDAO dao = new RemoteDAO();
       public void callDAO(){
              try{
              System.out.println( dao.sayHello() );
              catch( Exception e ){
    }

    >
    That's only a good idea if the semantics of sayHello
    as defined in MyInterface suggest that a
    RemoteException could occur. If not, then you're
    designing the interface to suit the way the
    implementing classes will be written, which smells.
    :-)But in practice you can't make a call which can be handled either remotely or locally without, at some point, dealing with the RemoteException.
    Therefore either RemoteException must be part of the interface or (an this is probably more satisfactory) you don't use the remote interface directly, but MyInterface is implemented by a wrapper class which deals with the exception.

  • Different Risk Analysis Results with the same user from 2 different RAR

    Hi..
    I've loaded the same Risks, Rules, etc, into 2 GRC RAR environments (Sandbox and Quality systems); both of them are connected with the same SAP ECC system. But when I do a User Risk analysis (authorization level), the result from Sandbox is different from Quality system. I donu2019t have users or roles mitigated yet, users are synchronized, rules are exactly the same and I donu2019t know what happen??... Please, help me.
    Thanks...

    Hi...
    If I do a Full Sync of users to the same ECC system from both RAR boxes, I got different number of users loaded (i.e. 18757 vs. 18141), similar case with the full sync of roles. (13100 vs.  13150).
    If I load exactly the same set of functions to both RAR systems and I generate the rules, I got the same problem, different number of rules is generated.
    I've verified both RAR configuration and they are the same (excluded users, roles mitigated, etc.)
    Is it a normal behavior? What could be wrong?
    Thanks in advance!!

  • Is it possible to call a function with the same name from 2 different dll's at the same time.

    I'm trying to call a function ( F ) form 2 different libraries ( A.dll and B.dll ) at the same time. The first lib loaded determines the function F. A->F and B->F have same interface and name but different implementation.

    Hi,
    I tried it with two dll's, both with the same interface, and at the same
    time, in the same VI. The popups even appear at the same time.
    But now I understand the problem... Both dll's are created by LabVIEW! If
    they are not (or one is not, and the other is), this is no problem.
    And VI's in memory cannot have the same name. LabVIEW doesn't care if VI's
    are in a dll or not.
    This might not help, but if you want to make some sort of "plug in" system,
    you might consider using llb's. By loading VI's dynamically, you can select
    the path from which they are loaded. You must unload (close all references)
    one before the loading the other, or the same problem will occur. If you go
    this way, I consider a different approach. Make on
    e library (or even a dll)
    that has the interface you like, this is the "loader". Now make several
    "plug in"'s, with the same interfaces. The name of each function in a plug
    in is a concatenation of the library name and the function name. The loader
    has one extra function, that loads (and unloads, when done) references to
    all desired libraries to use (the names of the functions can be figured out
    easily). All that the loader functions do is dynamically call the library
    functions. You can use a call by reference node for this (you can use the
    connector pane or the loader vi, since the interface must be the same!).
    If you go this way, I guess the loader library can be converted to a dll...
    Hope this helps.
    Wiebe.
    "rsam" wrote in message
    news:[email protected]..
    > Thx Wiebe,
    >
    > did you load both dll at the same time? For example in 1 vi. Somehow
    > the first loaded function keeps to overrule the second. Notice that
    > the interface is
    exactly the same.
    >
    > I loaded 2 dll created in Labview with results described above.
    >
    > Regards Ruud

  • Is possible search all the files in one folder and get list all with the same extension.??

    Hi,
    I would like to get, if it is possible, do searching in one determinate folder and get all the files with the same extension, For example, Give the *.pou and get all the files on one list of the files in this folder and sub-folders...
    If it is possible i would like to see any example.
    Thanks a lot, Fonsi.

    Hi Dennis,
    I got your advise, I download the openG (i had problems, and downloading directly and install one to one).
    Ok, i got but i have one problem, which i can't solve. I entry the promt  to search and put the directory to save, later i push 'Do it' and it search the files, show the paths and number, then save in the folder and finally show the window , all ok!.
    The problem is with the target path, when i want use the browse, it doesnt run properly. I want select one carpet, and it demands one file, i dont understand why??, i changed the options browse but it didnt work. Also i would like when i put one path if folder doesnt exist, directly create it and save the files, if exist copy it.
    Thanks for all!. I attached the file in lv 7.1
    Attachments:
    buscar3.vi ‏50 KB
    capture.GIF ‏48 KB

  • Songs with the same album art not grouped together in iTunes for Windows

    Brand new iTunes user here - do not yet have an iPod! (Needed some music only on iTunes)
    When I first started up iTunes, it imported all of my music I already had on my computer. A few of them are soundtracks with different artists.
    When they are shown in the iTunes library, the soundtracks have been broken up by Artist instead of staying as a whole album. How do I get the songs back together as one album? I found the folder on my computer where they are stored and combined them there, but they are still separate in the iTunes library.
    Thanks from a total newbie!

    Mark the tracks on the album as "Part of a compilation" and fill in the Album Artist field as "Various Artists". Click on the first track of your album to highlight it, hold down the shift key and click on the last track to highlight everything in between. Right click on the selection and choose Get Info. You'll get a message asking if you want to edit multiple items, say yes. If you are using iTunes 8 in the box that opens go to the Options tab and change "part of a compilation" to Yes and choose OK.
    Also in your library click on the title bar of album column to bring all the tracks in the same album together. If you keep clicking in the title you can choose it to sort by Album, Album by Artist or Album by Year. Clicking on the little triangle on the right side of the column header changes the sort direction. Pointing up and the column is sorted in Ascending order (A to Z). Pointing down and the column is sorted in Descending order (Z to A).
    You can also have a look at this article: Why aren't songs with the same album art grouped together

  • Has anyone sent their iPhone to be repaired only to get it back with the same problems it had before it was sent off?

    Hi all.
    I reported two problems to Apple about my iPhone 4S. The first being that the 3G stopped working (my phone has never been dropped, damaged or gotten wet) and the second that it keeps making a random and incessant beeping sound that can only be described as a "warning tone" even though no notification pops up on the screen and after going through all of the preset tones on the phone, I couldn't find one that matches.
    I know that it's not my service provider's fault in regards to the 3G as I've put my SIM card in a friend's iPhone who is on the same network and the 3G worked perfectly fine.
    This isn't my gripe, my gripe is that after having explained this to Apple and sending them my phone (I still have about 40 days of my one year warranty), I received it back a few days later with the exact same problems!!!
    Has anyone else sent their iDevice off to get "fixed" only to find out that all they did was repackage your item and send it back to you?

    See if you can force the phone into recovery mode:
    Leave the USB cable connected to your computer, but NOT your phone, itunes running, press & hold the home button while connecting the USB cable to your dock connector, continue holding the home button until you see “Connect to iTunes” on the screen. You may now release the home button. iTunes should now display that it has detected your phone in recovery mode, if not quit and reopen iTunes. If you still don’t see the recovery message repeat these steps again. iTunes will give you the option to restore from a backup or set up as new. Select restore from backup, follow by syncing your itunes content.

  • Grown InDesign files with the same content from 40 MB to 430 MB

    Hello
    I have a recurring project where always the same pdfs with vector contents are included. The InDesign file had always around 40 MB.
    Since the update to CC the new .indd files suddenly grew to 230 MB, and at the next step to 430 MB.
    I resave the files under a new name, when new corrections come in, so i can go back to the last version and track changes, there are about 120 pages, with about 60 tables and 35 graphics that were opened and colored in CMYK in Illustrator.  From the 40 to the 430 MB nothing has changed on my course of action... How can that be what I can do?
    Thank you!
    Hallo,
    ich habe ein wiederkehrendes Projekt in dem immer die gleichen pdfs mit Vektor Inhalt enthalten sind. Die InDesign Datei dazu hatte immer um die 40 MB.
    Seit dem update auf CC sind die neuen .indd Dateien plötzlich auf 230 MB gewachsen, und beim nächsten abspeichern dann auf 430 MB.
    ich speichere die Dateien, wenn ein Schwung Korrekturen kommt immer neu ab, damit ich zur letzten Version zurückkehren kann, deshalb kann ich nachverfolgen, wann die Daten so gewachsen sind... der Inhalt ist immer gleich, es sind ca. 120 Seiten, mit ca. 60 Tabellen und 35 Grafiken, die als pdf mit Illustrator geöffnet und dort in CMYK eingefärbt wurden. Von den 40 bis zu den 430 MB hat sich an meiner Vorgehensweise nichts geändert... wie kann das sein, was kann ich dagegen tun?
    Danke!

    It's sometimes best when changing version of Indesign to use File>Export and choose IDML
    then open that in the new version of Indesign.
    You can do this with your current files and see if the problem is fixed.

  • When i open a website, i get two tabs with the same address but different icons?

    when i open a webiste, i use google, another tab for the same website appears but with a different logo. macafee says it's not a virus, and to contact firefox.
    i am not a computer person and i don't know how to get rid of the second tab
    appreciate any help! :-)

    Can you attach a screenshot?
    *http://en.wikipedia.org/wiki/Screenshot
    *https://support.mozilla.org/kb/how-do-i-create-screenshot-my-problem
    Use a compressed image type like PNG or JPG to save the screenshot.
    Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions (Firefox/Tools > Add-ons > Extensions) or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance).
    *Do not click the Reset button on the Safe mode start window or otherwise make changes.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

  • When i open a website, i get two tabs with the same website but different icons?

    <blockquote>Locking duplicate thread.<br>
    Please continue here: [[/questions/938844]]</blockquote>
    i am not sure how else to explain it- i open a link on firefox and then 2 tabs open for the same site

    Can you attach a screenshot?
    *http://en.wikipedia.org/wiki/Screenshot
    *https://support.mozilla.org/kb/how-do-i-create-screenshot-my-problem
    Use a compressed image type like PNG or JPG to save the screenshot.
    Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions (Firefox/Tools > Add-ons > Extensions) or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance).
    *Do not click the Reset button on the Safe mode start window or otherwise make changes.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

  • OneDrive for Business/SharePoint API - GET folders 'shared with me' if shared from a group/s.

    Does anybody have any ideas of how to get the list of folders shared with a user from a group?
    I can already retrieve files shared with a user from another user with:
    https://{tenant}-my.sharepoint.com/_api/search/query?querytext='(SharedWithUsersOWSUSER: {account_name} AND contentclass:STS_ListItem_MySiteDocumentLibrary)'
    but this end point does not show any of the files if they were shared from a group, is this possible with the REST API?
    Thanks for any help in advance.

    Hi SpringComp,
    You can change the root path for libraries you sync to your computer, though you can do this only if you’re not currently syncing any libraries. If you’re already syncing at least one library and you want to change the path, you must first
    stop syncing all libraries. Then, the first time you run the OneDrive for Business wizard to sync a library to your computer, you’ll see an option to change the location.
    More information, please refer to the link:
    http://office.microsoft.com/en-001/support/change-the-location-where-you-sync-sharepoint-libraries-on-your-computer-HA102893480.aspx
    I hope this helps.
    Thanks,
    Wendy
    Wendy Li
    TechNet Community Support

  • Having multiple threads in ios 8.1 with the same people in a group message.

    When I send an imessage out to a group, some of the group responses will come back through a different message with all the same people. This just means I have 3-4 different threads in my messages with all of the same people. It's also difficult to read if I get multiple and check them at a later time because I have to see when they came through to piece the conversation together. Anyone else?

    Hello mollyh7,
    I would start with checking the your settings in Settings > Messages and as long as Group Messages is turned on you are good. But also keep in mind that if anyone else in the group does not have this enabled then it does throw everything off. Take a look at the article below for more information. 
    Send a group message with your iPhone, iPad, or iPod touch
    http://support.apple.com/kb/HT5760
    Regards,
    -Norm G. 

  • Getting only name of the physical disk from cluster group

    hi experts,
    i want to know the name of my cluster disk example - `Cluster Disk 2` available in a cluster group. Can i write a command something like below.
    Get-ClusterGroup –Name FileServer1 | Get-ClusterResource   where  ResourceType is Physical Disk
    Thanks
    Sid
    sid

    thanks Chaib... its working.
    However i tried this
    Get-ClusterGroup
    ClusterDemoRole
    | Get-ClusterResource
    | fl name
    |  findstr
    "physical Disk"
    which is also working.
    sid

Maybe you are looking for

  • How can I store history of certain websites for ever?

    So I like to read Manga but I keep forgetting which chapter i am on of the manga in question, i got 10's of manga on my current read list that get now and then updated. And firefox deletes the history after so many pages doesn't it? I get the feel it

  • Adobe livecycle ES installation problem

    Hi All, I'm facing a problem in the Adobe livecycleES installation. I have installed Adobe Acrobat 9 Pro Extended and proceeded to install livecycle ES 8.2.1. My installation is frozen after I select turn key installation. Waited for 1 hour, but does

  • How to draw this line

    I want to draw a link like this, how can I do it. I've been struggling for ages. this here is just a seriers or 5 pixel lines which I know isn't the right way

  • Core Audio Bug?

    Hello, Was persuaded recently to splash out on Core Audio compliant third party I/F for protools (Metric Halo). But it seems that Core Audio can't support 96kHz for Aggregate devices. Does anyone know anything about this? Metric Halo have been very h

  • Nik software en Photoshop CS5

    Buenas. Antes de nada, disculpas si esta entrada ya está respondida, pero he dado varias vueltas y no encuentro nada que me pueda ayudar. Tengo el pack de "Nik software", pero por más que lo instalo, mi Photoshop no lo lee, no me lo muestra... Dice q