Returning a case sensitive record

4

I have a constraint in the bank that is all with its capitalized name. How do I count find it using UPPER ? Because I want to pass where a lowercase name to return. This my query is not working.

select count(*)
 from all_cons_columns
 where UPPER(constraint_name) = 'FK_od8ou6g1l9t7iufcp3o0to189';

That is, return 0 when it should return 1. If I put the name as it is in the database it returns 1.

    
asked by anonymous 31.08.2017 / 20:17

2 answers

5

If you want to compare all uppercase then compare with the other side all uppercase too:

select count(*)
 from all_cons_columns
 where UPPER(constraint_name) = 'FK_OD8OU6G1L9T7IUFCP3O0TO189';

In fact it would be ideal to use COLLATE that does not consider casing in>. See article on the subject .

If it were a variable as a parameter there would be:

select count(*)
 from all_cons_columns
 where UPPER(constraint_name) = UPPER(parametro);

If it is guaranteed that the column will always be uppercase would be:

select count(*)
 from all_cons_columns
 where constraint_name = UPPER(parametro);

Anything that runs away from it makes no sense. Anyway it is a palliative, using the collation is the most correct.

    
31.08.2017 / 20:23
0

The solution was to pass UPPER on the constraint name:

select count(*)
 from all_cons_columns
 where constraint_name = UPPER('FK_od8ou6g1l9t7iufcp3o0to189');
    
31.08.2017 / 20:33