In a large set of queries, fired in succession through a script, a single query uses REGEXP_LIKE. In it I do not want the regexp ([a-z]) to match diacritics (á, õ, ì). The only way I found to do this, is setting NLS_SORT to BINARY. However, this query should not affect any other query run afterwards.
For this reason, I want to set the variable NLS_SORT only for this query. However, I would rather not resort to PL/SQL. Is there any way to achieve this?
I would prefer this, but according to the docs I found, no such parameter exists:
SELECT * FROM dual WHERE REGEXP_LIKE('ë', '[a-z]', BINARY);
I can imagine something like this:
SELECT * FROM dual WHERE REGEXP_LIKE('ë', '[a-z]'); -- match
ALTER SESSION SET NLS_SORT = BINARY;
SELECT * FROM dual WHERE REGEXP_LIKE('ë', '[a-z]'); -- no match
ALTER SESSION SET NLS_SORT = DEFAULT; -- not working
ALTER SESSION RESET NLS_SORT; -- not working
- Is there any other way to have the regular expression exclude diacritics than to set NLS_SORT?
- Is there any way to restore the NLS_SORT settings without PL/SQL?
So, thanks to Alex Poole, I reevaluated the
match_paramater
option in REGEXP_LIKE. From the documentation:Although case-sensitive would not seem to affect whether a matches á or e matches ë, here is stated that if a sort is case-sensitive, it's also accent-sensitive:
This states that all accent-insensitive sorts are case-insensitive, and therefore implicitly that a case-sensitive sort must be accent-sensitive.
So, in conclusion:
SELECT * FROM dual WHERE REGEXP_LIKE('ë', '[a-z]', 'c');