G-3195
🆓Error
Always use wildcards in a LIKE clause.
Reason
Using like without at least one wildcard (% or _) is unclear to a maintainer whether a wildcard is forgotten or it is meant as equality test. A common antipattern is also to forget that an underscore is a wildcard, so using like instead of equal can return unwanted rows. If the char datatype is involved, there is also the danger of like not using blank padded comparison where equal will. Depending on use case, you should either remember at least one wildcard or use normal equality operator.
Example
Non-Compliant Example
select e.employee_id
,e.last_name
from employees e
where e.last_name like 'Smith';Issues
| Line | Column | Message |
|---|---|---|
| 4 | 8 |
Compliant Solution - ★★★★★
select e.employee_id
,e.last_name
from employees e
where e.last_name like 'Smith%';Using a wildcard:
Change to equality operator instead:
select e.employee_id
,e.last_name
from employees e
where e.last_name = 'Smith';References
- same as plsql:S3643
- same as Trivadis G-3195
- same as plsqlopen:UnnecessaryLike