The underline has a meaning similar to the percentage sign in condition LIKE
SQL. Both are wildcards.
The difference is as follows:
- % looking for zero or more occurrences of any character;
- _ looking for one or more occurrences of any character.
For example, suppose we have a table with a column called word, and that the table has the following registered words:
class, class, class, class, class
Then the results of the queries will be the following
... where PALAVRA like '%cat%'
-- retorna acata, categoria, catraca, escatologia, mercator
... where PALAVRA like '_cat_'
-- retorna acata
-- Combinando os dois agora:
... where PALAVRA like '%_cat_%'
-- retorna acata, escatologia, mercator
To search for the wildcard characters themselves, you must escape them with a backslash. Your Where clause should look like this:
... where NM_CAMPAIGN like '%\_R\_%'
This goes for the three main DBMS: SQL Server, Oracle and Mysql.
Which one
SGBD
?– Sorack
That’s why the character
_
is also a SQL wildcard character. If you need it literal, you need to escape it.– Woss
I use SQL Server Management Studio.
– devin
Reinforcing for future readers:(Wildcard - matches a character) (Transact-SQL)
– Marconi
@Marconi put this reference in the answer
– Sorack