Oracle Fuzzy Search with spaces - oracle

I want to do fuzzy search in Oracle but query is not working with spaces.
ex. Let say we have a table po_test_tmp which has many records
If we execute this query it works fine
select score(1), ae.po_number
from po_test_tmp ae
where CONTAINS(po_number, 'fuzzy(po, 50,5000, weight)', 1)> 0
order by score(1) desc;
But if we try to search term like PO 123 it with not work
select score(1), ae.po_number
from po_test_tmp ae
where CONTAINS(po_number, 'fuzzy(PO 123, 50,5000, weight)', 1)> 0
order by score(1) desc;
ORA-29902: error in executing ODCIIndexStart() routine
ORA-20000: Oracle Text error:
DRG-50901: text query parser syntax error on line 1, column 10
29902. 00000 - "error in executing ODCIIndexStart() routine"
*Cause: The execution of ODCIIndexStart routine caused an error.
*Action: Examine the error messages produced by the indextype code and
take appropriate action.
How to do fuzzy search if search term has spaces, and search term can have special character and multiple spaces.

First please check the documentation of the Fuzzy operator
Parameter term - Specify the word on which to perform the fuzzy expansion.
Note that a term typically does not contain blank and you'll have to split your search in searate terms.
Additionally note that fuzzy to be activated, the term must have at least 3 characters. So your example with PO will not work.
What you can do for your setup is to define an extra fuzzy search for each part of your fuzzy string and combine them with the near operator such as follows
contains(po_number,'near (( fuzzy(word1,,,weight),fuzzy(word2,,,weight) ), 2, TRUE)',1) > 0
near enforces here that both matches must be adjacent (span = 2) and ordered (TRUE).
The handling of special characters depends on the definition of your whitespace and printjoins in your preference.

Related

Updating oracle records that starts with special char

I have below table dim_ethernet which has a column 5G_ON_AIR_DT
. I have to update its value from programming so I have written syntax in below style .
I got an error while running the code.
Does any one know how to write this code properly.
update ORA.dim_ethernet
set "5G_ON_AIR_DT" =: 5G_ON_AIR_DT
WHERE SITE_DWKEY =: SITE_DWKEY;
Seems like you are very new to Oracle world. Couple of things that are worth considering.
Your Query:
update ORA.dim_ethernet
set "5G_ON_AIR_DT" =: 5G_ON_AIR_DT
WHERE SITE_DWKEY =: SITE_DWKEY;
Points:
=: makes no sense as it is not valid in either SQL or PLSQL.
:= is an assignment operator in PLSQL.
= is assignment operator in SQL
PLSQL and SQL are two different engines but work together flawlessly giving an impression that they are one and the same. But in fact, they are not.
:some_val acts as a bind variable.
Using "column_name" is bad. Objects in Oracle are not case sensitive and if you put any object name inside double quotes, then it becomes case sensitive. There is no need to make your column name case sensitive.
That said, post the sample data and expected output. You will receive the best replies on the forum to handle what you are doing.
You have an identifier 5G_ON_AIR_DT.
From the Database Object Names and Qualifiers documentation:
Nonquoted identifiers must begin with an alphabetic character from your database character set. Quoted identifiers can begin with any character.
Since your identifier does not begin with an alphabetic character it cannot be used as a non-quoted identifier and always must be used with quotes.
You also have syntax errors with the =: and should be using = instead.
This would give you the query:
UPDATE ORA.dim_ethernet
SET "5G_ON_AIR_DT" = "5G_ON_AIR_DT"
WHERE SITE_DWKEY = SITE_DWKEY;
(Note: this statement will update the rows where SITE_DWKEY is not NULL and modify the 5G_ON_AIR_DT column to be its current value; so appears to be a pointless operation but would now be syntactically valid.)
db<>fiddle here

What are the wildcard characters present in Oracle?

In ORACLE what are the wildcard characters present I want to know ? I have been seeing this tutorial from w3schools and they have listed Wildcard Characters in MS Access and Wildcard Characters in SQL Server.
What about ORACLE?
I have checked ORACLE DOCUMENTATION but there are no wildcard characters present.
If there are wildcard characters present then :
1: What are the equivalent wildcard characters of (^ , #, !) present in ORACLE?
2: How can I use them in ORACLE syntax?
SELECT *
FROM Customers
WHERE City LIKE '[!bsp]%';
What should be the oracle equivalent text of the above code using wildcard ?
You seem to be asking about "wildcard characters" in comparing text strings (as opposed to, for example, the asterisk used in select * from ...). If so: Oracle has the LIKE operator, where the only wildcard characters are percent and underscore, and REGEXP_LIKE (and other regular expression functions) where the wildcard characters are the same as in the POSIX extended regular expression standard.
I have found one solution for the same query in Oracle SQL;
Problem Link: https://www.hackerrank.com/challenges/weather-observation-station-6/problem?h_r=next-challenge&h_v=zen
Question: Query the list of CITY names starting with vowels (i.e., a, e, i, o, or u) from STATION. Your result cannot contain duplicates.
Solution:
SELECT DISTINCT(CITY) FROM STATION WHERE REGEXP_LIKE (CITY,'^(A|E|I|O|U).') ;*
Here's the link where I found a relevant solution.
https://docs.oracle.com/cd/B19306_01/server.102/b14200/conditions007.htm

How to identify column types during sql injection?

Situation is following:
I have identified sql injection attack vector, and have following information about target table:
It has six columns. (Identified using "order by").
I can see output of 3 of them (table is displayed). two seems kind of enum value (integer in database?), and one is a date. I have very strong suspicion that col #6 is date column.
I'm almost sure the database is oracle. (ROWNUM works and LIMIT gives error).
I don't have error messages (always generic text is returned - "something went wrong").
Frontend is PHP if that matters. But there might be middle layer between it and database (e.g. java service), so I'm not sure where the query is being constructed.
E.g. following search query works as expected:
test' AND ROWNUM <= 5 ORDER BY 6--
EDIT-FROM-HERE:
Ok after help from comments, following query works:
test' UNION ALL SELECT null,null,null,null,null,null FROM dual--
(I was missing FROM dual part. Thank you #kordirko very much!)
This query adds one empty record in the output table (it is visually visible), so I'm definitely on the right track!
Now following line also works:
test' UNION ALL SELECT null,null,null,n't',null,null FROM dual--
I correctly identified 4th column and now it displays uppercase(?) letter T where I expected it to appear. So far so good. But it gives error when I input any string longer than 1 char! So following gives an error:
test' UNION ALL SELECT null,null,null,n'test',null,null FROM dual--
I'm no expert in SQL injection, and especially ORACLE (though have experience with MsSql).
I think the problem is something unicode-ansi-whateverencoding-related. For other rows (selected by original query before my UNION ALL SELECT addition) the 4th column gives multi-character normal strings. But when I try to inject desired string, it only works if it's one character, and also misteriously displays it in uppercase. I think this must be some encoding problem. I just discovered I needed n prefix for unicode string after 1 hour of searching and struggling. Maybe some Oracle gurus can quickly spot what mistake do I have in my query?

How to create a table out of the existing table?

So I am having a big table of AbstractID, SentenceID, WordID, and Word. Some words show in multiple files. I would like to count how many files every word shows, and then create a new table of with Word and Count. Below is a piece of my data.
My sql query is below:
CREATE TABLE WORDLIST(WORD, TOTALCOUNT) AS
(
SELECT WORD FROM ASSIGNMENT2 WHERE
(
SELECT WORD, COUNT(*) FROM (select DISTINCT FILEID, WORD FROM ASSIGNMENT2)
GROUP BY WORD ORDER BY COUNT(*) DESC));
It is giving me an error:
"Error report:
SQL Error: ORA-00936: missing expression
00936. 00000 - "missing expression"
*Cause:
*Action:"
How do I correct this? Thanks.
You're rather overcomplicating the query. The error is because your outer where clause doesn't have a condition; you're selecting multiple things, which isn't right anyway, but then not comparing those to anything. And you don't need to enclose the query in a set of parentheses.
You can just do:
CREATE TABLE WORDLIST (WORD, TOTALCOUNT) AS
SELECT WORD, COUNT(DISTINCT FILEID)
FROM ASSIGNMENT2
GROUP BY WORD;
There's no point ordering the query as it won't affect future queries against the new table - you still have to order those, as there is no inherent order of rows within the table. (And I think an order by will cause an error in a create-as statement, but can't immediately check that).
Creating a table to hold this information seems odd though as it will go out of date quickly. Perhaps you wanted a view really?

oracle database contains with "in%"

While working with one of the oracle query, when i am firing a select command with where condition something like:
select * from table_name where contains(address,'"IN%" AND "BÖDEN%"') >0
No results are shown as part of this query though results are there in database.
Again if i introduce one space between "IN" and "%" i am getting results in proper:
select * from table_name where contains(address,'"IN %" AND "BÖDEN%"') >0
There is one more scenario :
Same type of query but if "IN" is replaced with "IM" the corresponding results are displayed.
select * from table_name where contains(address,'"IM%" AND "BÖDEN%"') >0
or
select * from table_name where contains(address,'"IM %" AND "BÖDEN%"') >0
Both above queries are giving same results. which is quite obvious too.
Hence i suspect there is something speacial with "IN" in oracle.
Can anybody suggest me proper reason for this problem and any resolution for the problem ?
The IN keyword is a stop word in the default Stoplist which is used to specify the words which are not be indexed in Oracle Text.
You need to remove it from the stop list in order to search such stop words.
Check the link for Stoplist
Also please find the other default Stop words for English in oracle for your reference Default Stop words

Resources