I need to select some rows in SQLite with case insensitive string. For example:

COLLATE NOCASE is working for "=", e.g.

SELECT id,name from trait WHERE name = "ratio" COLLATE NOCASE

But is not working for "in", e.g.

SELECT id,name from trait WHERE name in ("ratio") COLLATE NOCASE

I have to use "in" to select multiple values, e.g.

SELECT id,name from trait WHERE name in ("ratio", 'number') COLLATE NOCASE 

How should I change my SQL script? Thanks for any suggestions.

有帮助吗?

解决方案 2

How about

SELECT id,name 
FROM trait 
WHERE UPPER(name) IN ("RATIO")

其他提示

The COLLATE NOCASE must appear directly after the expression it modifies.

When you write name in ("ratio", 'number') COLLATE NOCASE, the collation is applied to the result of the comparison, which is just a number 0 or 1; a collation has no effect there.

The IN operator uses the collation of the expression on its left side, so this is where the collation must be applied:

... WHERE name COLLATE NOCASE IN ('ratio', 'number')
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top