Oracle DB: How can I write query ignoring case?

前端 未结 8 1957
情歌与酒
情歌与酒 2020-12-05 16:48

As I had written in title, I have SQL query, run on Oracle DB, lets say:

SELECT * FROM TABLE WHERE TABLE.NAME Like \'IgNoReCaSe\'

If I woul

相关标签:
8条回答
  • 2020-12-05 17:22
    Select * from table where upper(table.name) like upper('IgNoreCaSe');
    

    Alternatively, substitute lower for upper.

    0 讨论(0)
  • 2020-12-05 17:22

    You can convert both values to upper or lowercase using the upper or lower functions:

    Select * from table where upper(table.name) like upper('IgNoreCaSe')
    

    or

    Select * from table where lower(table.name) like lower('IgNoreCaSe');
    
    0 讨论(0)
  • 2020-12-05 17:26

    You can use either lower or upper function on both sides of the where condition

    0 讨论(0)
  • You can use ALTER SESSION statements to set comparison to case-insensitive. See this FAQ.

    alter session set NLS_COMP=ANSI;
    alter session set NLS_SORT=BINARY_CI;
    

    For all those visiting 8 years after this original answer has been accepted (for 10gR2):

    After 10gR2, the NLS_COMP setting must be `LINGUISTIC':

    ALTER SESSION SET NLS_COMP=LINGUISTIC;
    
    0 讨论(0)
  • 2020-12-05 17:30

    You can use the upper() function in your query, and to increase performance you can use a function-base index

     CREATE INDEX upper_index_name ON table(upper(name))
    
    0 讨论(0)
  • 2020-12-05 17:43

    You could also use Regular Expressions:

    SELECT * FROM TABLE WHERE REGEXP_LIKE (TABLE.NAME,'IgNoReCaSe','i');
    
    0 讨论(0)
提交回复
热议问题