我有一个包含大小写字符的字符串,如何忽略大小写敏感性。
我尝试过使用COLLET、UPPERCASE和LOWERCASE,但都无效。是否还有其他方法可以忽略大小写?
我有一个包含大小写字符的字符串,如何忽略大小写敏感性。
我尝试过使用COLLET、UPPERCASE和LOWERCASE,但都无效。是否还有其他方法可以忽略大小写?
试试这个:
WHERE UPPER(myColumn) = UPPER(myValue)
WHERE LOWER(myColumn) = LOWER(myValue)
虽然使用大写和小写方法是可以的,但如果您正在寻找更复杂的东西,请尝试这个方法。
create table table_test (a varchar2(100));
insert into table_test values( 'ABC');
insert into table_test values( 'abc');
insert into table_test values( 'AbC');
alter session set NLS_COMP=LINGUISTIC;
-- how to compare string
alter session set NLS_SORT=BINARY_AI; --//or alter session set NLS_SORT=BINARY_CI;
-- how to sort string
-- the magic starts here
select * from table_test where a = 'ABC'
以下是不同排序和比较方法的完整描述: https://docs.oracle.com/cd/B28359_01/server.111/b28298/ch5lingsort.htm#CIHJBFAD
如Robert Kock所述,可以在两侧使用大写或小写字母。如果使用大写/小写后连接不匹配,则可能是数据中存在尾随空格的原因。在这种情况下,您也可以使用trim去除不需要的尾随空格。
upper(trim(column1)) = upper(trim(column2))
或者
lower(trim(column1)) = lower(trim(column2))
WHERE UPPER(myColumn) = UPPER(myValue)
这样的语句。当然,使用LOWER
也可以。 - Robert Kock