tags:

views:

120

answers:

5
+2  Q: 

question in sql

Hello, how I can create a query in Oracle for "angel" no matter if it is Angel, ANGEL, angel AngEl

+7  A: 

If you are matching the full value of the field use

WHERE UPPER(fieldName) = 'ANGEL'

EDIT: From your comment you want to use:

SELECT 
    RPAD(a.name, 10,'=') "Nombre del Cliente"
    , RPAD(b.name, 12,'*') "Nombre del Consumidor" 
FROM 
    s_customer a, 
    s_region b 
WHERE 
    a.region_id = b.id 
    AND UPPER(a.name) LIKE '%SPORT%'
Gary.Ray
You are great!!! thank you!
wanna by jaj, if Gary's answer solved your problem, you should accept is as the answer. :-)
Pablo Santa Cruz
If the customer table is large it would be worth considering adding a function-based index on upper(name) for this type of query.
Tony Andrews
+2  A: 

You can use:

select * from your_table where upper(your_column) like '%ANGEL%'

Otherwise, you can use:

select * from your_table where upper(your_column) = 'ANGEL'

Which will be more efficient if you are looking for a match with no additional characters before or after your_column field as Gary Ray suggested in his comments.

Pablo Santa Cruz
Agreed. Like is most concise.
hypoxide
@ PSC - Your where clause will only match if a variation of 'angel' with no additional characters before or after it is in the field. If that is the case then '=' is more efficient than 'LIKE'. See the OP comment.
Gary.Ray
+1  A: 

You could use the UPPER keyword:

SELECT *
FROM Customers
WHERE UPPER(LastName) = UPPER('AnGel')
bendewey
A: 

I don't recall the exact syntax, but you can actually set the table column to be case insensitive. But be careful because then you won't be able to match based on case anymore and if you WANT 'cool' to not match 'CoOl' it will no longer be possible.

Dr.Dredel
I don't think it is possible to set a column to be case insensitive in Oracle.
tuinstoel
I may be mistaken. I know it's an option in mySql
Dr.Dredel
+1  A: 

More detail on Mr Dredel's answer and tuinstoel's comment. The data in the column will be stored in its specific case, but you can change your session's case-sensitivity for matching.

You can change either the session or the database to use linguistic or case insensitive searching. You can also set up indexes to use particular sort orders.

eg

ALTER SESSION SET NLS_SORT=BINARY_CI;

Once you start getting into non-english languages, with accents and so on, there's additional support for accent-insensitive. Some of the capabilities vary by version, so check out the Globablization document for your particular version of Oracle. The latest (11g) is here

Gary