I’ve got a problem which seems simple at first, but really isn’t. I’m storing words in a table in such way that pair of strings “A B C D E” and “D E F” becomes:
id value
-- -----
1 A
1 B
1 C
1 D
1 E
2 D
2 E
2 F
And i pass to my ORACLE procedure string which looks like this: “A B C D G”. And now I want to check percentage of similarity between strings in the database and string passed as a parameter.
I presume that I have to use one of split functions and use an array. Later check if every word in passed string occurs in the table and then count ids. But there`s a twist: I need precise percentage value.
So, result from example above should look like this:
id percentage
-- ----------
1 80 -- 4 out of 5 letters exists in query string (A B C D)
2 33 -- 1 out of 3 (D)
So, my questions are:
- what is most effective way to split query string and then iterate on it (table?)
- how to store partial results and then count them?
- how to count final percentage value?
Every help would be greatly appreciated.
The following query would give you what you want without the need to bother with procedures.
Alternatively if you have to pass the string “A B C D G” and get a result back you could do:
These do involve full scanning the table or an index full scan if you use the suggested index below, so you might want to add the following where clause if you only want to find
idsthat have a percentage > 0.For all the queries your table should be indexed on
my_table, idin that order.