How to perform case-insensitive search in Oracle? (2024)

'; var adpushup = adpushup || {}; adpushup.que = adpushup.que || []; adpushup.que.push(function() { adpushup.triggerAd(ad_id); });

Problem:

You want to perform case-insensitive search in Oracle.

Solution

One way to deal with case issues is to use the built in UPPER and LOWER functions. These functions let you force case conversion on a string for a single operation

Example

DECLARE full_name1 VARCHAR2(30) := 'roger federer'; full_name2 VARCHAR2(30) := 'ROGER FEDERER';BEGIN IF LOWER(full_name1) = LOWER(full_name2) THEN DBMS_OUTPUT.PUT_LINE( full_name1 || ' and ' || full_name2 || ' are the same.'); END IF;END;

In the above example the full_name1 and full_name2 are first converted into LOWER CASE then compared with each other resulting the output

roger federer and ROGER FEDERER are the same.

There is one disadvantage with UPPER and LOWER functions, which is performance. Any function applied on a field will degrade performance.

Starting with Oracle Database 10g Release 2 you can use the initialization parameters NLS_COMP and NLS_SORT to render all string comparisons case insensitive.

We need to set the NLS_COMP parameter to LINGUISTIC, which will tell the database to use NLS_SORT for string comparisons. Then we will set NLS_SORT to a case insensitive setting, like BINARY_CI.

By default, NLS_COMP is set to BINARY. we can use LEAST function to see if the the uppercase characters sort lower than the lowercase characters or the other way.

Example

SELECT LEAST ('ROGER FEDERER','roger federer') FROM dual;

The above SQL returns ‘ROGER FEDERER’ telling us that uppercase characters sort lower than the lowercase characters.

Now, we are going to set couple of paramters.

  1. Set NLS_COMP to specify that a linguistic sort.
  2. Set NLS_SORT to specify the sorting rules that we want.

Example

ALTER SESSION SET NLS_COMP=LINGUISTICALTER SESSION SET NLS_SORT=BINARY_CI

After we set above settings to the session, we will call LEAST one more time to see what it returns.

Example

SELECT LEAST ('ROGER FEDERER','roger federer') FROM dual;

Output

roger federer

Finally, we will call the pl/sql block above with out applying the UPPER and LOWER functions to compare the strings.

Example

DECLARE full_name1 VARCHAR2(30) := 'roger federer'; full_name2 VARCHAR2(30) := 'ROGER FEDERER';BEGIN IF full_name1 = full_name2 THEN DBMS_OUTPUT.PUT_LINE( full_name1 || ' and ' || full_name2 || ' are the same.'); END IF;END;

roger federer and ROGER FEDERER are the same.

The settings will remain untile you close the session.

Updated on: 05-Dec-2020

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started

How to perform case-insensitive search in Oracle? (31)

Advertisem*nts

';adpushup.triggerAd(ad_id); });

How to perform case-insensitive search in Oracle? (2024)

FAQs

How to make an Oracle query case-insensitive? ›

We need to set the NLS_COMP parameter to LINGUISTIC, which will tell the database to use NLS_SORT for string comparisons. Then we will set NLS_SORT to a case insensitive setting, like BINARY_CI. By default, NLS_COMP is set to BINARY.

How do I make SQL search case-insensitive? ›

Another way for case-insensitive matching is to use a different “collation”. The default collations used by SQL Server and MySQL do not distinguish between upper and lower case letters—they are case-insensitive by default. The logic of this query is perfectly reasonable but the execution plan is not: DB2.

Which functions can be used to make your queries case-insensitive? ›

Case insensitive SQL SELECT: Use upper or lower functions

or this: select * from users where lower(first_name) = 'fred'; As you can see, the pattern is to make the field you're searching into uppercase or lowercase, and then make your search string also be uppercase or lowercase to match the SQL function you've used.

Is null case-sensitive in Oracle? ›

No, Null is not case-sensitive. is NULL and is null will always produce the same result.

How to make Oracle password case-insensitive? ›

In previous Oracle Database releases, you could configure the authentication protocol so that it allows case-insensitive password-based authentication by setting SEC_CASE_SENSITIVE_LOGON=FALSE .

How do you make the Find command case-insensitive? ›

By passing the name of the file using the -name flag, the find command searches and returns the location of the file. But remember the -name flag performs a case-sensitive search. If you are looking to do a case-insensitive search, you can use the -iname flag instead.

How do I make my search bar case-insensitive? ›

Your best bet would be to tweak the query and add syntax to upper case (or lower) both the search term and the data. That way you achieve your desired result. Hi Jonathan, Yes you can do it using both side ToUpper() or ToLower() function in your filter condition.

How do I turn off case-sensitive in SQL? ›

MySQL will look for objects names in with the exact case sensitivity as written in the query. You can turn off table name case sensitivity in MySQL by setting the parameter lower_case_table_names to 1. Column, index, stored routine, event names, and column aliases aren't case sensitive on either platform.

Is Oracle case-sensitive by default? ›

Oracle names aren't case sensitive. PostgreSQL names are case sensitive. By default, AWS SCT uses object name in lower-case for PostgreSQL.

How do you make a function not case sensitive? ›

To ignore case in JavaScript, you can use one of the following methods: The toLowerCase() or toUpperCase() methods: These methods convert a string to all lowercase or uppercase characters, allowing you to perform case-insensitive comparisons.

Which function was used to perform case-insensitive comparison? ›

The strcasecmp() function compares, while ignoring differences in case, the string pointed to by string1 to the string pointed to by string2. The string arguments to the function must contain a NULL character (\0) marking the end of the string. The strcasecmp() function is locale-sensitive.

Which function performs a case sensitive lookup? ›

By default, the VLOOKUP function performs a case-insensitive lookup. However, you can use INDEX, MATCH and EXACT in Excel to perform a case-sensitive lookup.

How to create a case-sensitive table in Oracle? ›

By default, Oracle identifiers (table names, column names, etc.) are case-insensitive. You can make them case-sensitive by using quotes around them (eg: SELECT * FROM "My_Table" WHERE "my_field" = 1 ). SQL keywords ( SELECT , WHERE , JOIN , etc.)

Are keywords case-sensitive in Oracle? ›

Keywords and phrase strings are not case-sensitive. Keywords which are not enclosed within quotes must contain only alphanumeric characters, underscore ( _ ), and wildcard characters ( * , % , and ? ).

Is Like case-sensitive in Oracle? ›

The default behaviour of LIKE and the other comparison operators, = etc is case-sensitive.

How do I change case sensitive in SQL? ›

For case-sensitive searches in SQL Server, use COLLATE keyword with the case sensitive collation “SQL_Latin1_General_CP1_CS_AS” followed by the LIKE or = comparisons as usual.

How do you make a string case-insensitive? ›

To ignore case in JavaScript, you can use one of the following methods: The toLowerCase() or toUpperCase() methods: These methods convert a string to all lowercase or uppercase characters, allowing you to perform case-insensitive comparisons.

How to use case condition in Oracle query? ›

In a searched CASE expression, Oracle searches from left to right until it finds an occurrence of condition that is true, and then returns return_expr . If no condition is found to be true, and an ELSE clause exists, then Oracle returns else_expr . Otherwise, Oracle returns null.

How to change case in Oracle SQL? ›

In newest versions you can highlight the text and then go to: Tools >> PL/SQL Beautifier and this will format your query and uppercase the text! Hope it helps.

Top Articles
Latest Posts
Article information

Author: Allyn Kozey

Last Updated:

Views: 6589

Rating: 4.2 / 5 (63 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Allyn Kozey

Birthday: 1993-12-21

Address: Suite 454 40343 Larson Union, Port Melia, TX 16164

Phone: +2456904400762

Job: Investor Administrator

Hobby: Sketching, Puzzles, Pet, Mountaineering, Skydiving, Dowsing, Sports

Introduction: My name is Allyn Kozey, I am a outstanding, colorful, adventurous, encouraging, zealous, tender, helpful person who loves writing and wants to share my knowledge and understanding with you.