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
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).
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é
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%')
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