Oracle Contains Query Returning False Positives - oracle

I am trying to search for names in a clob field in oracle using contains. I know the text I am testing this on contains 'Joe Smith' with one space in between Joe and Smith, so this query works returns the records when I run it:
SELECT *
FROM case_search
WHERE contains(text, 'Joe Smith', 1) > 0
The issue is that this query, with two spaces between Joe and Smith, is also returning the text as a hit but the text only has 'Joe Smith' with one space and not 'Joe Smith' with two spaces:
SELECT *
FROM case_search
WHERE contains(text, 'Joe Smith', 1) > 0
I can add as many spaces as I would like in between Joe and Smith and it still returns a hit. I need to add the name that hit in the exact form to another table in order for something to work later. Can anyone explain what is happening here and how to fix it?

Related

How to Get the details after the space in REGEXP_SUBSTR in oracle 11g

I just want some help in my script. I have a 2 types of values in my data the first one is
first-order, Delivery Date: 04/18/2020 AM, OOS: Find similar item
The other one is
third-order, Delivery Date:04/19/2020 AM, OOS: Find similar item
I already get the "04/19/2020" after the word "Delivery Date:" in the second example.
My problem is how can I get the date "04/18/2020" after the word "Delivery Date:" in the first value.
Here is what I came up to get the value of the second example.
select REGEXP_SUBSTR(column_name,'Date:([[:alnum:]]+\.?){1,10}........?') from mytable
What other way to get the value after the space or additional function in my existing script.
Thank you. Appreciate your help.
Use the following regex pattern:
Delivery Date:\s*(\S+)
This matches the contents after delivery date, also allowing for an optional space separator after the colon.
SQL code:
SELECT
col,
REGEXP_SUBSTR(col, 'Delivery Date:\s*(\S+)', 1, 1, NULL, 1) AS "date"
FROM mytable;
Demo

Is there a function to search for partial text in cells

I have a function that searches a spreadsheet for a name I put in cell A1 and returns a column in that row
eg, if I enter Smith in A1 it will return all columns C´s where Column D contains Smith, I would also like it to return columns containing smith so if a cell as john smith it would also be returned,
this is what I have so far but it only returns Total match,
=FILTER(Results!C:C,Results!$D:$D=$A$1)
Hope someone can help,
Thanks in advance
I believe this is what you're trying to do:
=filter(Results!C:C,find(lower($A$1),lower(Results!D:D))>=0)
EDIT: adding the lower() function to make the comparison case insensitive.

Writing Active record to search based on all values in a table field

I want to search based on all locations , i am storing locations as a cookie.
I want to search and get result like this, list properties in locations Delhi NCR or Mumbai or Pune or Hyderabad or Bangalore or Chennai or Coimbatore or Cochin
I've written an active record like this:
#location = cookies[:location_id] (here iam getting all locations)
#properties=Property.where("location LIKE ?", "%#{#location}%")
So, I got sql query like this:
SELECT * FROM `properties` WHERE (location LIKE '%Delhi NCR,Mumbai,Pune,Hyderabad,Bangalore,Chennai,Coimbatore,Cochin%')`
seperated by comma, and also not getting search result if any location name is present in table.
how to search according to all locations and list if any present?
Please help.
Any help is appreciatable
#location = cookies[:location_id]
#properties=Property.where("location IN (?)", #location.split(","))
Try this

Oracle query with two paterns in one expression

Input:
TABLE NAME: SEARCH_RECORD
Column A Column B Column C Column D
ID CODE WORD CODE/WORD
--------------------------------------------
123 666Ani RAT 666Ani/RAT
124 777Cae CAT 777Cae/CAT
I need a query to check as a LIKE case
if i search with column B like '%6A' or column C '%A%' it will give result
suppose i want to get the like based on the column D search
**User will search like '%6A%'/'%AT%' (always / will be given by user)**
Expected output:
666Ani/RAT
so, I need a query for the above to get the ID as output (CASE query is preferable)
Need you valuable suggestion
.
It can't be done with simple like.
It should work if the pattern look like '%6A%/%AT%'. It is a valid pattern.
So, you can write: columnD like '%6A%/%AT%' or columnD like first_pattern||'/'||second_pattern if the come from as different variables.
Another approach, if you know for sure that there is only a /(you can check how many they are), may be to use two likes using substr to get first and then second part of the search string.
where
columnB like substr(match_string, 1, instr(match_string,'/'))
and
columnC like substr(match_string, instr(match_string,'/')+1)

Oracle full text, the syntax of CONTAINS()

contains(columnname, 'ABC')=0
this means search for the data which doesn't contain word 'ABC'
contains(columnname, 'ABC and XYZ')=0
contains(columnname, 'ABC or XYZ')=0
what do these 2 sql mean? I tested them, there's no syntax error, but they didn't work as I expected, the 'and' seems like an 'or', and 'or' seems like an 'and', could anyone help to explain this?
all doc found in google are for contains()>0, those're not what I need.
thanks in advance.
According to oracle documentation, the contains function :
returns a relevance score for every row selected
If you ask for
contains(columnname, 'ABC')=0
You actually ask for a score of 0 which means: columnname doesn't contain 'ABC'
According to the docs:
In an AND query, the score returned is the score of the lowest query term
In an OR query, the score returned is the score for the highest query term
So if you ask for:
contains(columnname, 'ABC and XYZ')=0
then if either 'ABC' or 'XYZ' has a score of 0 it will have the lowest score and that's what you'll get from the function, so you're actually asking for: columnname doesn't contain 'ABC' or 'XYZ' (at least one of them).
Same thing for the or -
contains(columnname, 'ABC or XYZ')=0
only if both 'ABC' and 'XYZ' have the score of 0 the function will return 0, so you're actually asking for: columnname doesn't contain 'ABC' and 'XYZ' (both of them).
IMHO, this behaviour is correct since it meets De-Moragan's Laws

Resources