REGEXP_ compare two tokenized strings

Hi,
I need to compare two fields (from two tables), to see if any of the tokenized contents match.
I have two tables with a "name" field, but the names might be incomplete or in random order. To get a match, I just need 1 part of both to really match, for example "John Doe" should match to "Doe J.".
Something like:
SELECT names1.name, names2.name
FROM names1, names2
WHERE INSTR(names1.name, REGEXP_SUBSTR(names2.name, '[[:alpha:]]+')) > 0
But the statement should consider all tokens, not just the first one as in the example.
Any suggestion on how to achieve this?
Thanks,
K.

The performance of the regexp_instr in the where clause is terrible ... I stopped working out other scenarios, because the conclusion will be the same:
SQL> create table names1
  2  as
  3  select 1 id, 'John Doe' name from dual union all
  4  select 2, 'Larry Ellison' from dual union all
  5  select 3, 'Catharina-Amalia Beatrix Carmen Victoria van Oranje' from dual union all
  6  select object_id, o
  7    from ( select object_id
  8                , owner || object_name o
  9                , ntile(200) over (order by object_id) nt
10             from all_objects
11         )
12   where nt = 11
13  /
Tabel is aangemaakt.
SQL> create table names2
  2  as
  3  select 1001 id, 'Doe J.' name from dual union all
  4  select 1002, 'Gates Bill' from dual union all
  5  select 1003, 'Beatrix Wilhelmina Armgard van Oranje' from dual union all
  6  select object_id, o
  7    from ( select object_id
  8                , owner || object_name o
  9                , ntile(200) over (order by object_id) nt
10             from all_objects
11         )
12   where nt = 22
13  /
Tabel is aangemaakt.
SQL> select count(*) from names1
  2  /
  COUNT(*)
       241
1 rij is geselecteerd.
SQL> select count(*) from names2
  2  /
  COUNT(*)
       241
1 rij is geselecteerd.
SQL> exec dbms_stats.gather_table_stats(user,'names1')
PL/SQL-procedure is geslaagd.
SQL> exec dbms_stats.gather_table_stats(user,'names2')
PL/SQL-procedure is geslaagd.
SQL> set timing on
SQL> set autotrace on
SQL> select distinct n1.original_name name1
  2       , n2.original_name name2
  3    from ( select id
  4                , name
  5                , original_name
  6             from names1
  7            model
  8                  return updated rows
  9                  partition by (id)
10                  dimension by (0 i)
11                  measures (' ' || name || ' ' name, cast(null as varchar2(100)) original_name)
12                  rules iterate (100) until (iteration_number = length(regexp_replace(name[0],'[^ ]')) - 2)
13                  ( name[iteration_number+1] = regexp_substr(name[0],'[^ ]+',1,iteration_number+1)
14                  , original_name[iteration_number+1] = trim(name[0])
15                  )
16         ) n1
17       , ( select id
18                , name
19                , original_name
20             from names2
21            model
22                  return updated rows
23                  partition by (id)
24                  dimension by (0 i)
25                  measures (' ' || name || ' ' name, cast(null as varchar2(100)) original_name)
26                  rules iterate (100) until (iteration_number = length(regexp_replace(name[0],'[^ ]')) - 2)
27                  ( name[iteration_number+1] = regexp_substr(name[0],'[^ ]+',1,iteration_number+1)
28                  , original_name[iteration_number+1] = trim(name[0])
29                  )
30         ) n2
31   where n1.name = n2.name
32  /
NAME1
NAME2
Catharina-Amalia Beatrix Carmen Victoria van Oranje
Beatrix Wilhelmina Armgard van Oranje
John Doe
Doe J.
2 rijen zijn geselecteerd.
Verstreken: 00:00:00.07
Uitvoeringspan
   0      SELECT STATEMENT Optimizer=CHOOSE (Cost=8 Card=581 Bytes=987
          70)
   1    0   SORT (UNIQUE) (Cost=8 Card=581 Bytes=98770)
   2    1     HASH JOIN (Cost=7 Card=581 Bytes=98770)
   3    2       VIEW (Cost=3 Card=241 Bytes=20485)
   4    3         BUFFER (SORT)
   5    4           SQL MODEL (ORDERED FAST)
   6    5             TABLE ACCESS (FULL) OF 'NAMES1' (TABLE) (Cost=3
          Card=241 Bytes=5784)
   7    2       VIEW (Cost=3 Card=241 Bytes=20485)
   8    7         BUFFER (SORT)
   9    8           SQL MODEL (ORDERED FAST)
  10    9             TABLE ACCESS (FULL) OF 'NAMES2' (TABLE) (Cost=3
          Card=241 Bytes=5784)
Statistics
        387  recursive calls
          0  db block gets
         52  consistent gets
          0  physical reads
          0  redo size
        590  bytes sent via SQL*Net to client
        508  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
         11  sorts (memory)
          0  sorts (disk)
          2  rows processed
SQL> select n1.name name1
  2       , n2.name name2
  3    from names1 n1
  4       , names2 n2
  5   where regexp_instr  ( ' ' || n1.name || ' ',       ' ' || replace( n2.name, ' ', ' | ' ) || ' '  ) > 0
  6  /
NAME1                                                        NAME2
John Doe                                                     Doe J.
Catharina-Amalia Beatrix Carmen Victoria van Oranje          Beatrix Wilhelmina Armgard van Oranje
2 rijen zijn geselecteerd.
Verstreken: 00:00:46.54
Uitvoeringspan
   0      SELECT STATEMENT Optimizer=CHOOSE (Cost=218 Card=2904 Bytes=
          121968)
   1    0   NESTED LOOPS (Cost=218 Card=2904 Bytes=121968)
   2    1     TABLE ACCESS (FULL) OF 'NAMES1' (TABLE) (Cost=3 Card=241
           Bytes=5061)
   3    1     TABLE ACCESS (FULL) OF 'NAMES2' (TABLE) (Cost=1 Card=12
          Bytes=252)
Statistics
          1  recursive calls
          0  db block gets
        728  consistent gets
          0  physical reads
          0  redo size
        590  bytes sent via SQL*Net to client
        508  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          2  rows processedRegards,
Rob.

Similar Messages

  • How to Compare two strings in PL/SQL

    Hi All,
    I need to compare two strings whether they are equal or not in PL/SQL.Is there any function to comparing the strings.

    Yes, the = sign.
    Are you after something like:
    IF v_string1 = v_string2 THEN
    ELSE
    END IF;?
    Edited by: Boneist on 27-Aug-2009 11:41

  • Compare two string in different line in textarea

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class TextCounterPanel extends JPanel {
    private JTextArea textInput;
    private JLabel lineCountLabel;
                        public TextCounterPanel() {
                        setBackground(Color.DARK_GRAY);
                        textInput = new JTextArea();
                        textInput.setBackground(Color.WHITE);
                        JPanel south = new JPanel();
                        south.setBackground(Color.DARK_GRAY);
                        south.setLayout( new GridLayout(4,1,2,2) );
                             JButton countButton = new JButton("Process the Text");
                             countButton.addActionListener( new ActionListener() {
                                  public void actionPerformed(ActionEvent evt) {
                                       processInput();
                             south.add(countButton);
                        lineCountLabel = new JLabel(" Number of lines:");
                        lineCountLabel.setBackground(Color.WHITE);
                        lineCountLabel.setForeground(Color.BLUE);
                        lineCountLabel.setOpaque(true);
                        south.add(lineCountLabel);
                        setLayout( new BorderLayout(2,2) );
                        setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY));
                        JScrollPane scroller = new JScrollPane( textInput );
                        add(scroller, BorderLayout.CENTER);
                        add(south, BorderLayout.SOUTH);
    public void processInput() {
    String text,vin; // The user's input from the text area.
    text = textInput.getText();
    vin =text.substring(25,42);
    lineCountLabel.setText(" vin: " + vin);
    } // end class TextCounterPanel
    How can I compare two string in different line in text area

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class TextCounterPanel extends JPanel {
    private JTextArea textInput;
    private JLabel lineCountLabel;
    public TextCounterPanel() {
    setBackground(Color.DARK_GRAY);
    textInput = new JTextArea();
    textInput.setBackground(Color.WHITE);
    JPanel south = new JPanel();
    south.setBackground(Color.DARK_GRAY);
    south.setLayout( new GridLayout(4,1,2,2) );
    JButton countButton = new JButton("Process the Text");
    countButton.addActionListener( new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
    processInput();
    south.add(countButton);
    lineCountLabel = new JLabel(" Number of lines:");
    lineCountLabel.setBackground(Color.WHITE);
    lineCountLabel.setForeground(Color.BLUE);
    lineCountLabel.setOpaque(true);
    south.add(lineCountLabel);
    setLayout( new BorderLayout(2,2) );
    setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY));
    JScrollPane scroller = new JScrollPane( textInput );
    add(scroller, BorderLayout.CENTER);
    add(south, BorderLayout.SOUTH);
    public void processInput() {
    String text,vin; // The user's input from the text area.
    text = textInput.getText();
    vin =text.substring(25,42);
    lineCountLabel.setText(" vin: " + vin);
    } // end class TextCounterPanel

  • Compare two strings in a formula

    Hi,
    I'd like to know if there's a way to compare two strings in a formula ?
    I have this consition:
    IF(@SUBSTRING(@NAME(@CURRMBR(TIME_FROM)),5)==@NAME(@CURRMBR(TIME)))
    But the == operator can only compare two data.
    Thanks,
    Cyril

    Hi,
    thank you both for your answers.
    When I figured that the == operator was for data only, I didn't even try to compare member names.
    I finally used the solution that Cameron suggested in another conversation. I created a date measure, and loaded some data since the beginning of my time to the end.
    It starts in 1974 (annually), then becomes monthly data, and then daily data from 2009, so it's not so many blocks to br created. In the end I have the same value for "from 2008"/"from Apr 30", and I can easily compare my dates.
    Note that I could have also used the @TODATE function, which turns a date into a number, but the format of date is limited and doesn't fit the format of my member names, so I got lasy... and I'm not sure my users would have apreciated that ;)
    Thanks, this post is solved.
    Cyril

  • Compare two strings for partial or full match

    I have been trying to figure out away of comparing two strings.
    I can get the full string matching to successfully work but am struggling on how to get partial eg wildcard search working.
    say I had names like paul Duncan, George Morrison.
    I have split them up so its now paul , duncan i then use the users entered string to compare it against the name name to see if it matches anything in the first name or the last name if it does i added it to an arraylist.
    however i have tried t use a indexof as i believe this looks for similarity (Substring matches?) but it always returns -1.
    Could anyone possibly direct me to a method that will allow me to use partial text string to match it against stored user names.
    eg user enters pa
    I would return anything that would contain pa
    thanks for any help

    thank you for the reply
    Sorry I forgot to put in the code.
    This is a reduced down version including the read in from a text file as well as the index of if statement and the adding of it to an array list.
    public class FindContact {
    String res;
    /** Creates a new instance of FindContact */
    public FindContact() {
    public Object[] FindAUser(String passSearch) {
    System.out.println("getting here");
    ArrayList found = new ArrayList();
    String patternStr = ",";
    int j, i = 0;
    try {
    BufferedReader in = new BufferedReader(new FileReader("H:\\out.txt"));
    String str;
    while ((str = in.readLine()) != null) {
    String[] fields = str.split(patternStr);
    //for(j=0;j < fields.length;j++) {
    if (fields.length != 0) {
    if (passSearch.indexOf(fields[0])!=-1 || passSearch.indexOf(fields[1])!=-1) {
    found.add(str);
    System.out.println("ENDDDDDDDD value ");
    in.close();
    } catch (IOException e) {
    System.out.println(e.toString());
    Object[] foundResult = new Object[found.size()];
    foundResult = found.toArray();
    if (foundResult.length >= 0) {
    System.out.println(foundResult.length);
    return foundResult;
    Hope that helps as it has confused me and am not sure why it is not returning a value.
    Should I maybe use the contain method instead to search for the user inputted string?

  • Compare two strings and the save the greater

    To devolop a vi,it can compare two strings.A string is gived,the other is saved previously.If greater,then save,or do nothing.

    Hi,
    I am assuming by "greater" you mean the string length.
    Use the string length function from the strings palette, with shift-registers on a while loop. Write to the shift-register the "greater" string.
    I am attaching a diagram screenshot for this. NOTE: depending on how you want this VI to run, you can move the input and output string control and indicator inside our outside the while loop.
    Hope this is what you were looking for.
    Khalid
    Attachments:
    strlen.gif ‏17 KB

  • How to compare two strings whether both are equal while ignoring the difference in special characters (example: & vs & and many others)?

    I attempted to compare two strings whether they are equal or not. They should return true if both are equal.
    One string is based on Taxonomy's Term (i.e. Term.Name) whereas other string is based on String object.
    The problem is that both strings which seem equal return false instead of true. Both string values have different special characters though their special characters are & and &
    Snapshot of different design & same symbols:
    Is it due to different culture or language?
    How to compare two strings whether both are equal while ignoring the difference in special characters (& vs &)?

    Hi Jerioon,
    If you have a list of possible ambiguous characters the job is going to be easy and if (& vs &) are the only charracters in concern awesome.
    You can use the below solution.
    Before comparing pass the variables through a replace function to standarize the char set.
    $Var = Replace($Var,"&","&")
    This is going to make sure you don't end up with ambiguous characters failing the comparison and all the char are "&" in this case.
    Similar technique is used to ignore Character Cases 'a' vs. 'A'
    Regards,
    Satyajit
    Please “Vote As Helpful”
    if you find my contribution useful or “Mark As Answer” if it does answer your question. That will encourage me - and others - to take time out to help you.

  • Compare two strings in an array

    Hello!
    Please feel free to give me hints, but do not give me any code.
    Ok, here is what I am trying to do, I whant to compare my input string whith strings allready stored in the array. If my input string equals any of the allready excisting strings, a error wil show upp, otherwise store the new string in next avalibal position. I do not seem to get the method right for comparing the strings. here is the method I have written so far, please take a look and give me a hint, but no code. :)
    //Check if a user already excists     
    public void compareNames (People in_array [], String in_name) {
              for (int i=0; i<value.peopleCount; i++) {
                   if (in_name.equals(in_array.getPeople())) {
                   System.out.print("The user already excist, please chose another name");
    }value.peopleCount is an global count value for people arays.
    getPeople get the name from the people class.
    Martin                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    A couple notes here.
    The name compareNames() is misleading if it is going to do what you described. A comparison will generally not have side-effects like outputting error messages to the console or adding new items to an array. It would be better if you called the method addIfNew(), and returned a boolean indicating whether the name was new or not. The caller would then be responsible for displaying an error message if the method returned false.
    I also suggest you use a List such as ArrayList instead of an array, otherwise you will have to resize and copy your array every time you add something to it that exceeds the array size, and will allow you to do away with the global peopleCount.

  • How can i compare two excel files with different no. of records.

    Hi
    I am on to a small project that involves us to compare two excel files. i am able to do it but am struck up at a point. When i compare 2 different .csv files with different no. of lines i am only able to compare upto a point till when the number of lines is same in both the files.
    Eg. if source file has 8 lines and target file has 12 lines. The difference is displayed only till 8 lines and the remaining 4 lines in source lines are not shown.
    Can you help me in displaying those extra 4 lines in source file. I am attaching my code snippet below..
    while (((strLine = br.readLine()) != null) && ((strLine1 = br1.readLine())) != null)
                     String delims = "[;,\t,,,|]";
                    String[] tokens = strLine.split(delims);
                    String[] tokens1 = strLine1.split(delims);
                   if (tokens.length > tokens1.length)
                    for (int i = 0; i < tokens.length; i++) {
                        try {
                            if (!tokens.equals(tokens1[i])) {
    System.out.println(tokens[i] + "<----->" + tokens1[i]);
    out.write(sno + " \t" + lineNo1 + " \t\t" + tokens[i] + "\t\t\t\t" + tokens1[i]);
    out.println();
    sno++;
    } catch (Exception exception)
    out.write(sno + " \t" + lineNo1 + " \t\t" + tokens[i] + "\t\t\t\t" + "");
    out.println();
    Thanks & Regards                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    A CSV file is not an Excel file.
    But apart from that your logic makes no sense.
    If the 2 files are of different sizes the files are different by definition, so further comparison isn't needed, you're done.
    If you want to compare individual records, you need to compare all records from one file with all records from the other, unless the order of records is important in which case your current system might work.
    That system however is overly complicated for comparing CSV files.
    As you assume a single record per line, and if one can assume those records to have identical layout (so no leading or trailing whitespace in or between columns in one file that's not in the other) comparing records is simply a matter of comparing the entire lines.

  • Compare two input text in adf

    Hi
    i used the Build JDEVADF_11.1.1.4.0
    I want to make compare  validation between two  input text  Are equal or not . same Thing when i create new email i must enter the password and re enter password if not   equal  he give me message

    Hi,
    for a validation String, you can put autosubmit=true and in the valuechangeListener make the comparation.
    How to compare two Strings in java? http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java

  • How to compare two excel files in java ?

    how do i compare two excel files in java.?
    I have two excel files stored on my computer in d: drive.
    Ex:
    D:\\file a
    D:\\file b
    How to compare the contents of these two files and print " files are equal " or "files not equal "

    Javamastermahe wrote:
    I mean i want to print on the console "files are equal " or any message like " both the files match "If this is your requirement, this program satisfies it...
    import java.util.Random;
    public class SuperExcelTester {
        public static void main(String[] args) {
            Random rnd = new Random();
            String[] messages = {
                "files are equal",
                "files are not equal",
                "unexpected error"
            int index = rnd.nextInt(messages.length);
            System.out.println(messages[index]);
    }

  • How to compare two files in java & uncommon text should print in text file.

    Hi,
    Can any one help me to write Core java program for this.
    How to compare two files in java & uncommon text should print in other text file.
    thanks
    Sam

    Hi All,
    i m comparing two HTML file.. thats why i am getting problem..
    import java.io.BufferedReader;
    import java.io.FileReader;
    public class textmatch{
    public static void main(String[] argv)
    throws Exception{
    BufferedReader fh =new BufferedReader(new FileReader("internal.html"),1024);
    BufferedReader sh = new BufferedReader(new FileReader("external.html"),1024);
    String s;
    String y;
    while ((s=fh.readLine())!=null)
    if ( s.equals(y=sh.readLine()) ){    
    System.out.println(s + " " + y); //REMOVE THIS PRINTLN STATEMENT IF YOU JUST WANT TO SHOW THE SIMILARITIES
    sh.close();
    fh.close(); }
    thanks
    Sam

  • How to compare two files in Java & uncommon text should print in Diff text

    Hi All,
    can any one help me to write a java program..
    How to compare two files in Java & uncommon text should print in Diff text file..
    Thanks
    Sam

    Hi All,
    i m comparing two HTML file.. thats why i am getting problem..
    import java.io.BufferedReader;
    import java.io.FileReader;
    public class textmatch{
    public static void main(String[] argv)
    throws Exception{
    BufferedReader fh =new BufferedReader(new FileReader("internal.html"),1024);
    BufferedReader sh = new BufferedReader(new FileReader("external.html"),1024);
    String s;
    String y;
    while ((s=fh.readLine())!=null)
    if ( s.equals(y=sh.readLine()) ){    
    System.out.println(s + " " + y); //REMOVE THIS PRINTLN STATEMENT IF YOU JUST WANT TO SHOW THE SIMILARITIES
    sh.close();
    fh.close(); }
    thanks
    Sam

  • Compare two collection in sharepoint

    Hii
    I want to Compare to collection in sharepoint
    example:
    Collection 1: "A","B","C"
    Collection 2:"A","B","D","E"
    Result should be: "C"
    Like in C#  List<string> result = list1.Except(list2).ToList();
    I am new to programming Please help me..
    regards 
    sudeep

    http://stackoverflow.com/questions/3407356/comparing-two-collections
    check this example code below
    class CompareLists
    static void Main()
    // Create the IEnumerable data sources.
    string[] names1 = System.IO.File.ReadAllLines(@"../../../names1.txt");
    string[] names2 = System.IO.File.ReadAllLines(@"../../../names2.txt");
    // Create the query. Note that method syntax must be used here.
    IEnumerable<string> differenceQuery =
    names1.Except(names2);
    // Execute the query.
    Console.WriteLine("The following lines are in names1.txt but not names2.txt");
    foreach (string s in differenceQuery)
    Console.WriteLine(s);
    // Keep the console window open in debug mode.
    Console.WriteLine("Press any key to exit");
    Console.ReadKey();
    /* Output:
    The following lines are in names1.txt but not names2.txt
    Potra, Cristina
    Noriega, Fabricio
    Aw, Kam Foo
    Toyoshima, Tim
    Guy, Wey Yuan
    Garcia, Debra
    http://msdn.microsoft.com/en-us/library/bb397894.aspx
    Mark ANSWER if this reply resolves your query, If helpful then VOTE HELPFUL
    INSQLSERVER.COM
    Mohammad Nizamuddin

  • Compare two dates in different format.

    Hi
    I want to compare two dates....one of which is in the timeStamp format ("yyyy-MM-dd HH:mm:ss")
    and the other is in java.util.Date i.e Tue Oct 11 10:22:47 GMT+05:30 2005
    Do I have to tokenise and then compare them.Is there any better approach?
    I want to find out which is greater/smaller one.
    Pls help.
    Regards,
    Sandip.

    I would convert both to Date and compare them. To convert String to Date check java.text.SimpleDateFormat and its parse(...) method.
    HTH
    Mike

Maybe you are looking for

  • Invoice List: Missing Pricing Condition

    Hi, We are trying to implement invoice list because of the different sold-to party but same payer requirement. we have configured all the requirements listed Prerequisites You can only process invoice lists if the following prerequisite data is defin

  • Wireless Router and the Mac

    Quick question. I just installed a Linksys Wireless Router and voila, I am wirelessly connected. Right out of the box. Question: Are our Macs automatically protected from "outsiders" or do we have to do something manually? Re: One Intel iMac and one

  • IMac restarts instead of shutting down

    Hello, I have a 2009 iMac 24" running 10.6.2. When I select shutdown from the shutdown menu it asks if I want to shutdown and then after selecting yes it starts the shutdown process. After shutting down it immediately restarts. When selecting shutdow

  • How to remove background on image

    Hi I would like to make the background on the attached image white and to manipulate the silver jewellery on the image attached so that it shows up clearly against the white. I've tried all sorts of things but found that either the image blends into

  • Left Shift - w doesn't work

    I'm unable to get a capital w when I use the left shift key. I am able to capitalize every other letter with the left shift key and I can get a capital W with the right shift key and the caps lock button. Anybody have a similar experience or have any