您可以在SELECT查询中使用COLLATE NOCASE:
SELECT * FROM ... WHERE name = 'someone' COLLATE NOCASE
另外,在sqlite中,可以通过在列定义中指定collate nocase(其他选项为binary(默认值)和rtrim;请参见here)指示在创建表时不区分大小写。您也可以在创建索引时指定collate nocase。例如:
create table Test ( Text_Value text collate nocase ); insert into Test values ('A'); insert into Test values ('b'); insert into Test values ('C'); create index Test_Text_Value_Index on Test (Text_Value collate nocase);
涉及Test.Text_Value的表达式现在应该不区分大小写。例如:
sqlite> select Text_Value from Test where Text_Value = 'B'; Text_Value ---------------- b sqlite> select Text_Value from Test order by Text_Value; Text_Value ---------------- A b C sqlite> select Text_Value from Test order by Text_Value desc; Text_Value ---------------- C b A
优化器还可以潜在地利用索引对列进行不区分大小写的搜索和匹配。您可以使用explain sql命令检查此,例如:
sqlite> explain select Text_Value from Test where Text_Value = 'b'; addr opcode p1 p2 p3 ---------------- -------------- ---------- ---------- --------------------------------- 0 Goto 0 16 1 Integer 0 0 2 OpenRead 1 3 keyinfo(1,NOCASE) 3 SetNumColumns 1 2 4 String8 0 0 b 5 IsNull -1 14 6 MakeRecord 1 0 a 7 MemStore 0 0 8 MoveGe 1 14 9 MemLoad 0 0 10 IdxGE 1 14 + 11 Column 1 0 12 Callback 1 0 13 Next 1 9 14 Close 1 0 15 Halt 0 0 16 Transaction 0 0 17 VerifyCookie 0 4 18 Goto 0 1 19 Noop 0 0