Compare Strings ignoring accents in SQL (ORACLE)

后端 未结 4 1799
说谎
说谎 2020-12-17 20:36

I would like to know if there is an easy way to compare two text values ignoring the accents and upper case. Im working with an Oracle database. I already searched for an an

相关标签:
4条回答
  • 2020-12-17 20:50

    use the nlssort function in the following way:

    select * from <your_table> where utl_raw.cast_to_varchar2((nlssort(<inspected_column>, 'nls_sort=binary_ai'))) like 'pe%';
    

    The nlssort call transforms accented characters to their linguistic bases and ignores case in comparisons.

    Original source is this article (verified on 12c).

    0 讨论(0)
  • 2020-12-17 20:54

    Oracle Setup:

    CREATE TABLE TABLE_NAME ( value ) AS
    SELECT 'pepé' FROM DUAL;
    
    -- Not necessary to create an index but it can speed things up.
    CREATE INDEX value_without_accent_idx
      ON TABLE_NAME ( CONVERT( value, 'US7ASCII' ) );
    

    Query:

    SELECT *
    FROM   table_name
    WHERE  CONVERT( value, 'US7ASCII' ) = 'pepe';
    

    Output:

    VALUE
    -----
    pepé  
    
    0 讨论(0)
  • 2020-12-17 20:54

    From this thread you can do the following:

    select * from your_table 
    where upper(utl_raw.cast_to_varchar2((nlssort(your_column, 'nls_sort=binary_ai')))) like upper('%word%')
    
    0 讨论(0)
  • 2020-12-17 21:10

    This works for Ç and the rest of characters in PT-BR (Portuguese - Brazil):

    SELECT CONVERT( 'ÃÕÑ ÁÉÍ Ç', 'SF7ASCII' ) FROM DUAL;
    Result: **AON AEI C**
    

    Check your database version:

    SELECT * FROM V$VERSION;
       Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
        PL/SQL Release 11.2.0.1.0 - Production
        "CORE   11.2.0.1.0  Production"
        TNS for Linux: Version 11.2.0.1.0 - Production
        NLSRTL Version 11.2.0.1.0 - Production
    
    0 讨论(0)
提交回复
热议问题