Is it possible to use commodin in the left side of a LIKE operator? - sql

Is there a way to be able to use at least _ in the left side so the following statement returns 1:
SELECT 1 FROM DUAL WHERE
'te_ephone' like 'tele_ho%'
I want oracle to parse the left side as it parses the right one, to make _ match 'any' char. Is this possible or is there any workaround to make this work?
To give some context, the final objective is that things like remoñoson matchs with remonos%.
Left hand side is a column where I am replacing some characters by _ whilst the start with query with the same replacement.

Based on your context what you are expecting can be achieved using Linguistic Sort which gives detailed information about searching Linguistic strings and sorting
Example1(case-insensitive or accent-insensitive comparisons):-
SELECT word FROM test1
WHERE NLS_UPPER(word, 'NLS_SORT = XGERMAN') = 'GROSSE';
WORD
------------
GROSSE
Große
große
Example 2 using Regular expression with the Base Letter Operator [==]:-
Oracle SQL syntax:
SQL> SELECT col FROM test WHERE REGEXP_LIKE(col,'r[[=e=]]sum[[=e=]]');
Expression: r[[=e=]]sum[[=e=]]
Matches:
resume
résumé
résume
resumé

Related

Druid SQL: get substring issue

There is the table column which holds the comma-separated values, e.g:
abc321,rd512,spwewr
I need to extract the substring which starts from the user-defined pattern.
Example:
Input Pattern | Expected result
abc abc321
r rd512
spwe spwewr
b NULL
Following fails in Druid SQL:
SELECT SUBSTRING('abc321,rd512,spwewr', POSITION('r' IN 'abc321,rd512,spwewr'), 2)
This is the known Druid bug:
" Substring operator converter does not handle non-constant literals correctly":
https://issues.apache.org/jira/browse/CALCITE-2226
I think the way to go is to use REGEXP_EXTRACT() or REGEXP_LIKE()
but I cannot figure out the specific syntax.
select regexp_extract('abc321,rd512,spwewr', 'rd[^,]+', 0)

Find duplicates in case-sensitive query in MS Access

I have a table containing Japanese text, in which I believe that there are some duplicate rows. I want to write a SELECT query that returns all duplicate rows. So I tried running the following query based on an answer from this site (I wasn't able to relocate the source):
SELECT [KeywordID], [Keyword]
FROM Keyword
WHERE [Keyword] IN (SELECT [Keyword]
FROM [Keyword] GROUP BY [Keyword] HAVING COUNT(*) > 1);
The problem is that Access' equality operator treats the two Japanese writing systems - hiragana and katakana - as the same thing, where they should be treated as distinct. Both writing systems have the same phonetic value, although the written characters used to represent the sound are different - e.g. あ (hiragana) and ア (katakana) both represent the sound 'a'.
When I run the above query, however, both of these characters will appear, as according to Access, they're the same character and therefore a duplicate. Essentially it's a case-insensitive search where I need a case-sensitive one.
I got around this issue when doing a simple SELECT to find a Keyword using StrComp to perform a binary comparison, because this method correctly treats hiragana and katakana as distinct. I don't know how I can adapt the query above to use StrComp, though, because it's not directly evaluating one string against another as in the linked question.
Basically what I'm asking is: how can I do a query that will return all duplicates in a table, case-sensitive?
You can use exists instead:
SELECT [KeywordID], [Keyword]
FROM Keyword as k
WHERE EXISTS (SELECT 1
FROM Keyword as k2
WHERE STRCOMP(k2.Keyword, k.KeyWord, 0) = 0 AND
k.KeywordID <> k2.KeywordID
);
Try with a self join:
SELECT k1.[KeywordID], k1.[Keyword], k2.[KeywordID], k2.[Keyword]
FROM Keyword AS k1 INNER JOIN Keyword AS k2
ON k1.[KeywordID] < k2.[KeywordID] AND STRCOMP(k1.[Keyword], k2.[Keyword], 0) = 0

Trying to join Access tables with like statement with list in field

I have a problem that I have been hunting for a solution to, but to avail.
The basics are that I am trying to join 2 tables in Access by comparing a value in a field of Table 1 to a field in Table 2 that contains the number concatenated along with a few others in a list type format. (both fields are text type)
Example.
Table1.CWT value = 640242
Corresponding Table2.TAG_NO value I want to match to = 640242; 635894; 058426
So that it links the two tables based on the common value (640242 in this case).
So far, I have tried the following:
LEFT JOIN [Table2] ON [Table1].CWT like '*' & [Table2].TAG_NO & '*'
and
LEFT JOIN [Table2] ON [Table1].CWT & '*' like [Table2].TAG_NO
and what seems like every variation in between, I have even tried using % instead of *. But nothing works. In some cases, the value will be the second or third element in the string (635894 in above example), so I am looking for an option that will work in all cases. This is akin to looking for the equivalent of the CONTAINS function, but that does not seem to exist either.
Can anyone help me out?
Thanks
Ted
You need to switch the operands. And make sure that '640242' doesn't match '6402423', so add delimiters to both strings:
' ' & Table2.TAG_NO & ';' like '* ' & Table1.CWT & ';*'
You can use the Instr Function that tests if a string exists in other string as below:
Select [Table1].CWT, [Table1].OtherColumn, [Table2].Column1Needed,[Table2].Column2Needed
From [Table1], [Table2]
Where Instr([Table2].TAG_NO,[Table1].CWT)>0
See http://www.techonthenet.com/access/functions/string/instr.php

SQL FTS and comparison statements

Short story. I am working on a project where I need to communicate with SQLite database. And there I have several problems:
There is one FTS table with nodeId and nodeName columns. I need to select all nodeIds for which nodeNames contains some text pattern. For instance all node names with "Donald" inside. Something similar was discussed in this thread. The point is that I can't use CONTAINS keyword. Instead I use MATCH. And here is the question itself: how should this "Donald" string be "framed"? With '*' or with '%' character? Here is my query:
SELECT * FROM nodeFtsTable WHERE nodeName MATCH "Donald"
Is it OK to write multiple comparison in SELECT statement? I mean something like this:
SELECT * FROM distanceTable WHERE pointId = 1 OR pointId = 4 OR pointId = 203 AND distance<200
I hope that it does not sound very confusing. Thank you in advance!
Edit: Sorry, I missed the fact that you are using FTS4. It looks like you can just do this:
SELECT * FROM nodeFtsTable WHERE nodeName MATCH 'Donald'
Here is relevant documentation.
No wildcard characters are needed in order to match all entries in which Donald is a discrete word (e.g. the above will match Donald Duck). If you want to match Donald as part of a word (e.g. Donalds) then you need to use * in the appropriate place:
SELECT * FROM nodeFtsTable WHERE nodeName MATCH 'Donald*'
If your query wasn't working, it was probably because you used double quotes.
From the SQLite documentation:
The MATCH operator is a special syntax for the match()
application-defined function. The default match() function
implementation raises an exception and is not really useful for
anything. But extensions can override the match() function with more
helpful logic.
FTS4 is an extension that provides a match() function.
Yes, it is ok to use multiple conditions as in your second query. When you have a complex set of conditions, it is important to understand the order in which the conditions will be evaluated. AND is always evaluated before OR (they are analagous to mathematical multiplication and addition, respectively). In practice, I think it is always best to use parentheses for clarity when using a combination of AND and OR:
--This is the same as with no parentheses, but is clearer:
SELECT * FROM distanceTable WHERE
pointId = 1 OR
pointId = 4 OR
(pointId = 203 AND distance<200)
--This is something completely different:
SELECT * FROM distanceTable WHERE
(pointId = 1 OR pointId = 4 OR pointId = 203) AND
distance<200

Implement an IN Query using XQuery in MSSQLServer 2005

I'm trying to query an xml column using an IN expression. I have not found a native XQuery way of doing such a query so I have tried two work-arounds:
Implement the IN query as a concatenation of ORs like this:
WHERE Data.exist('/Document/ParentKTMNode[text() = sql:variable("#Param1368320145") or
text() = sql:variable("#Param2043685301") or ...
Implement the IN query with the String fn:contains(...) method like this:
WHERE Data.exist('/Document/Field2[fn:contains(sql:variable("#Param1412022317"), .)]') = 1
Where the given parameter is a (long) string with the values separated by "|"
The problem is that Version 1. doesn't work for more than about 50 arguments. The server throws an out of memory exception. Version 2. works, but is very, very slow.
Has anyone a 3. idea? To phrase the problem more complete: Given a list of values, of any sql native type, select all rows whose xml column has one of the given values at a specific field in the xml.
Try to insert all your parameters in a table and query using sql:column clause:
SELECT Mytable.Column FROM MyTable
CROSS JOIN (SELECT '#Param1' T UNION ALL SELECT '#Param2') B
WHERE Data.exist('/Document/ParentKTMNode[text() = sql:column("T")