Here is one for the tekkies. How to do this in SQL?

Input : String 541862356
Table has 2 columns:
SNO                             SLENGTH
5418                                4
54186                               5
54321                               5
Output should be 54186.
We don't have any other input. i.e. we have to get the closest match for the input string.
How to do this??
Edited by: user12240205 on May 3, 2012 10:51 PM

user12240205 wrote:
We don't have any other input. i.e. we have to get the closest match for the input string.You haven't explained what "closest match" actually means.
Something as simple as this could do what you want with the sample data you've provided...
SQL> ed
Wrote file afiedt.buf
  1  WITH t AS (SELECT 5418 sno, 4 cnt FROM DUAL UNION
  2             SELECT 54186, 5 FROM DUAL UNION
  3             SELECT 54321, 5 FROM DUAL)
  4      ,r as (select 541862356 as r from dual)
  5  --
  6  -- end of test data
  7  --
  8  select max(sno)
  9  from   t,r
10* where  instr(r, sno) > 0
SQL> /
  MAX(SNO)
     54186... without the need for any Henry Winkler matching stuff (as we affectionately call it round here).

Similar Messages

  • One for the Tekkies: How to get this output using REGULAR EXPRESSIONS?

    How to get the below output using REGULAR EXPRESSIONS??
    SQL> ed
    Wrote file afiedt.buf
      1* CREATE TABLE cus___addresses    (full_address                   VARCHAR2(200 BYTE))
    SQL> /
    Table created.
    SQL> PROMPT Address Format is: House #/Housename,  street,  City, Zip Code, COUNTRY
    House #/Housename,  street,  City, Zip Code, COUNTRY
    SQL> INSERT INTO cus___addresses VALUES('1, 3rd street, Lansing, MI 49001, USA');
    1 row created.
    SQL> INSERT INTO cus___addresses VALUES('3B, fifth street, Clinton, OK 74103, USA');
    1 row created.
    SQL> INSERT INTO cus___addresses VALUES('Rose Villa, Stanton Grove, Murray, TN 37183, USA');
    1 row created.
    SQL> SELECT * FROM cus___addresses;
    FULL_ADDRESS
    1, 3rd street, Lansing, MI 49001, USA
    3B, fifth street, Clinton, OK 74103, USA
    Rose Villa, Stanton Grove, Murray, TN 37183, USA
    SQL> The REG EXP query shouLd output the ZIP codes: i.e. 49001, 74103, 37183 in 3 rows.Edited by: user12240205 on Jun 18, 2012 3:19 AM

    Hi,
    user12240205 wrote:
    ... Frank, ʃʃp's method, I understand. But your method, although correct, I find it difficult to understand.
    Could you explain how you did this?? What does '.*(\d{5})\D*' and '\1' mean???
    Your method is better because it uses only ONE reg expression function. ʃʃp's uses 2.In Oracle 10.2 (I believe) and higher, '\d' is equivalent to '[[:digit:]]', and '\D' is equivalent to '[^[:digit:]]'. I find '\d' and '\D' easier to type, but there's nothing wrong with using '[[:digit:]]' and '[^[:digit:]]'.
    '.*' means "0 or more of any character".
    '\D*' means "0 or more non-digits".
    The whole expression, '.*(\d{5})\D*' means:
    a. 0 or more characters (any characters)
    b. 5 digits
    c. 0 or more non-digits.
    '\1' is a Backreference . It means the sub-string that matched the pattern after the 1st '(', up to (but not including) its matching ')'. In this case, that means the sub-string that matched '\d{5}', or b. using the explanation immediately above.
    So the entire REGEXP_REPLACE call means "When you see a sub-string consisting of a., follwed immediately by b., followed immedately by c., replace that sub-string with b. alone."

  • How can I use two single-dimensional arrays-one for the titles and array

    I want to Use two single-dimensional arrays-one for the titles and one for the ID
    Could everyone help me how can i write the code for it?
    Flower
    public class Video
    public static void main(String[] args) throws Exception
    int[][] ID =
    { {145,147,148},
    {146,149, 150} };
    String[][] Titles=
    { {"Barney","True Grit","The night before Christmas"},
    {"Lalla", "Jacke Chan", "Metal"} };
    int x, y;
    int r, c;
    System.out.println("List before Sort");
    for(c =0; c< 3; ++c)
    for(r=0; r< 3; ++ r)
    System.out.println("ID:" + ID[c][r]+ "\tTitle: " + Titles[c][r]);
    System.out.println("\nAfter Sort:");
    for(c =0; c< 3; ++c)
    for(r=0; r< 3; ++ r)
    System.out.println("ID:" + ID[c][r]+ "\tTitle: " + Titles[c][r]);

    This is one of the most bizarre questions I have seen here:
    public class Video
    public static void main(String[] args) throws Exception
    int[] ID = {145,147,148, 146,149, 150};
    String[] Titles= {"Barney","True Grit","The night before Christmas", "Lalla", "Jacke Chan", "Metal"};
    System.out.println("List before Sort");
    for(int i = 0; i < Titles.length; i++)
       System.out.println("ID:" + ID[i]+ "\tTitle: " + Titles);
    System.out.println("\nAfter Sort:");
    for(int i = 0; c < Titles.length; i++)
    System.out.println("ID:" + ID[i]+ "\tTitle: " + Titles[i]);
    Generally you don't use prefix (++c) operators in you for loop. Use postfix (c++).
    Prefix means that it will increment the variable before the loop body is executed. Postfix will cause it to increment after.

  • Hi, I need to take my daughter off from our Apple account and set up her own. So, delete her from one account and create her own. Realize I sound imbecilic for not knowing how to do this. Any ideas? Thank you so much. Jules

    Hi, I need to take my daughter off from our Apple account and set up her own. So, delete her from one account and create her own. Realize I sound imbecilic for not knowing how to do this. Any ideas? Thank you so much. Jules

    You don't have to take her off your account exactly: she needs to sign out from your account on her computers and devices. Then she can obtain an Apple ID at http://appleid.apple.com and use it to sign into System Preferences or Settings>iCloud.
    However, there are some issue about this. If she has been syncing her calendars and contacts to your account then the data will disappear from her devices, but remain on your account. Individual calendars can be exported  as .ics files and reimported into her account, but if she has her contacts mixed up with yours she will have to enter them individually in the new account (or export yours, import them into hers, and delete the ones she doesn't want.
    More intractable is the email issue. She cannot move an address from your account to hers, so if she has been using a alias on your account to have her own address she cannot transfer it. She will have to create a new email address.

  • How can I manage several ID on my computer, one for my iPhone and another one for the iPad of the family?

    Hi everybody
    Just have bought an ipad2 and i would like to manage several IDs on my computer (i.e keep my iPhone ID and create another one for the ipad to manage apps for my iPhone (4) and the apps for the iPad).
    How can I resetup the iPad to create that new ID on itunes?
    Thanks for your help
    Jp

    If you have separate iTunes accounts for the two devices then you'll need to buy 2 copies of any app that you want on both device - you can't copy or move apps from one account to another (they are tied to the account that bought/downloaded them). If you want to reset the iPad then logout of the account on it (Settings > Store and tap the id on the right-hand side) and then Settings > General > Reset > Erase All Content And Settings will reset it back to factory defaults.
    You may want to consider one of three options mentioned on this page http://support.apple.com/kb/HT1495

  • I have an apple ID for the South African iTunes store how do I get one for the US store?, I have an apple ID for the South African iTunes store how do I get one for the US store?

    I have an apple ID for the South african i Tunes store.  How do I get one for the US one?  I want to use Mind Snacks.

    You will need a valid billing address in the US and be in the US when you want to buy anything from it. You can try requesting that it be added to the South African, but ultimately it's the app's developer that will have to grant Apple a licence to sell it there : http://www.apple.com/feedback/itunes.html

  • HT4623 I have an ipad3, iPhone3gs and iPhone5, my problem is my apple ID works all 3 devices but I need a second ID for the iPhone 5. How do I delete my ID and set up a new one for the iPhone5 but keeping my own apple ID for the iPad and iPhone 3GS

    I have an ipad3, iPhone3gs and iPhone5, my problem is my apple ID works all 3 devices but I need a second ID for the iPhone 5. How do I delete my ID and set up a new one for the iPhone5 but keeping my own apple ID for the iPad and iPhone 3GS.

    http://support.apple.com/kb/he37

  • MAC OS Yosemite - CS6 - A while back, i did something to where when i open a file in photoshop, it no longer is one window, now it's two separete ones. one for the program itself, and another for the actual file how do it get it back to where it's all one

    - A while back, i did something to where when i open a file in photoshop, it no longer is one window, now it's two separete ones. one for the program itself, and another for the actual file how do it get it back to where it's all one window without having to be in full screen mode? I've managed to go some time like this, but right now it's just really annoying me. HELP!!!

    Just drag the small window to the top right below the toolbar, you'll see the area highlighted and when you drop it the file should dock.

  • Are not the right ones for the icloud account. How can I find out what these are?

    I have downloaded icloud onto my PC. When I try to access my account I am told that although my Apple ID and password are correct they are not the right ones for the icloud account.How can I find out what these are?

    Christine Helen wrote:
    I can't find any way of creating an icloud ID. I only have a PC. no Mac product except an iPod classic.
    Oh, then you can't unless you know someone with a Mac you could use for a moment or 2. (Like at the Apple Store)

  • I lost my iphone in the water I bought a new one 4S now I have 2 back ups in Icloud, the one for the new Iphne and the old Iphone where I have the most info I need. How I can download my old backup?

    I lost my iphone in the water I bought a new one 4S now I have 2 back ups in Icloud, the one for the new Iphne and the old Iphone where I have the most info I need. How I can download my old backup?

    Welcome to the Apple community.
    You cannot download a backup from iCloud, the only way to access it is to restore to the backup with your new phone, which you should have done when you first connected it. If you restore now, you will lose all the new information you have added to your new phone.

  • Just brought home newly purchased MacBook Pro 15"/Maverick/Retinal Display. To my astonishment, there is NO DVD slot! No one in the store told me about this missing feature. Intolerable, How does one install software? Insert CDs to copy for iTunes?Do I ha

    Just brought home newly purchased MacBook Pro 15"/Maverick/Retinal Display. To my astonishment, there is NO DVD slot! No one in the store told me about this missing feature. Intolerable, How does one install software? Insert CDs to copy for iTunes?Do I have to purchase an external DVD drive? Is one even available? What a crock!

    I’ve owned Macs since 1990 (IICX my first), mostly desktops. Having had DVD/CD drives in all my previous laptop Macs since 2001 -  (2) G4 Powerbooks,  A 17” Mac Book Pro - and also inspecting a friend’s year-old Mac Book Pro which had the DVD slot - unless someone told me at purchase, I had no reason to know that the Retina display version of the 15” had NO DVD drive. ANYHOW, I fully intended to buy the non-Retina display version, because it was cheaper. Unfortunately by the time I got to the Apple store they were no longer selling the non-Retina display version; all versions were ONLY with the Retina display. And the fine distinction of a DVD vs. a non-DVD drive was not pointed out. So now I have to shell out an additional $80 bucks for an external SuperDrive.

  • New firefoxis great. i keep many windows open. in ur earlier ver. I used to close it, it would ask for save and shut down as one of the three option,but in this new version it close all my window, how do i save my window tab?

    new firefox is great. I usually have many windows open. in your earlier version, when ever I used to close it, it would ask for save and shut down as one of the three option,but in this new version it close all my window, how do i save my window tab?

    See [[Firefox does not ask to save tabs and windows on exit]].
    Does this work for you?

  • My ipohne and ipad use the same account.  My wife wants to setup her own account for the ipad and utilize family sharing.  How can I change the account in my ipad?

    My ipohne and ipad use the same account.  My wife wants to setup her own account for the ipad and utilize family sharing.  How can I change the account in my ipad?

    Hi,
    Are you talking about changing the Apple ID used for purchases in iTunes? If so go to 'Settings->iTunes & App Store-> then 'tap' on the Apple ID that appears and click Sign Out on menu that appears. You can now login with a different Apple ID.
    Regards,
    Steve

  • In setting up my wifes phone it got my apple id for the cloud, how do I change it to her id?

    In setting up my wifes phone it got my apple id for the cloud, how do I change it to her id?

    Settings>iCloud>Delete Account.
    Then input her iCloud account

  • I have money on my ipod from gift card but play games on my gfs since hers is newer ios and i need to transfer money from my accounts existing gift card to her account to buy upgrades for the game how am i to do this?

    i have money on my ipod from gift card but play games on my gfs since hers is newer ios and i need to transfer money from my accounts existing gift card to her account to buy upgrades for the game how am i to do this?

    You cannot

Maybe you are looking for

  • How do I add a mail icon for my POP3/SMTP mail account?

    I have a mail account with POP3 incoming and SMTP out. How do I add an icon to Firefox 3.6.9 to link to this as would Outlook in IE?

  • Numbers coming out at "1n7" instead of "1.7" when using Java APIs

    I have an RTF template, and on the Text Form Field Options dialog in Word, I have the Number Format field set to "#,##0.00000". When this template is run from a concurrent program, or from the desktop plug-in, the numbers correctly format in the form

  • Opening mini bridge in Indesign

    I have the updated and full versions of Indesign and Bridge, however I want to open Mini bridge in Indesign to use the programmes together but when I go to the window button there is no option to open the Mini Bridge. Any advice on how to open mini b

  • Problem viewing .flv's on an external server

    I am working with the program eLMS Pro (http://www.elmspro.com/elms/) and I can upload my published file via zip to their server (no flvs in the zip due to the file size). I have placed my zip files on an other server in a folder which is my source u

  • Oracle RAC/3rd party clusterware support question

    Does anyone know if Oracle supports a Linux RAC system also running HP Ibrix clusterware? I was not able to find a list of certified 3rd party clusterware vendors that Oracle will support to run with RAC. If anyone has this information, please let me