Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching with LIKE '%_%'

Status
Not open for further replies.

nada1234

Technical User
Sep 27, 2002
1
US
I would like to search a field for the underscore character (ansi 95). The problem is that SQL thinks of the underscore character ( _ ) as a single character wildcard. If I say LIKE '%_%'it is the same as LIKE '%'. How can i search for an underscore?
 
You use the escape phrase

....like "%*_%" escape *

The asterisk (it could be any character in reality)
escapes the wildcard character - (underscore)

....like "%X_%" escape X

is just as valid

HTH
;-) Dickie Bird
db@dickiebird.freeserve.co.uk
 
You might try the following if your platform is Oracle

Code:
SELECT COLUMN1
       ,INSTR(COLUMN1,'_')  
FROM   ALL_TABLES 
WHERE  INSTR(TABLE_NAME,'_') > 0

Cheers
AA 8~)
 
Should have provided more of an explanation. INSTR is the Oracle position function. Other DBMS have similar. The query simply asks that the position of '_' is not zero, meaning not found.

Cheers again AA 8~)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top