SQL tutorial | Interview questions | Oracle
Would you like to react to this message? Create an account in a few clicks or log in to continue.

How To Use LIKE Conditions?

Go down

How To Use LIKE Conditions? Empty How To Use LIKE Conditions?

Post by Micheal Sat Jan 16, 2010 9:24 pm

LIKE condition is also called pattern patch. There 3 main rules on using LIKE condition:
'_' is used in the pattern to match any one character.
'%' is used in the pattern to match any zero or more characters.
ESCAPE clause is used to provide the escape character in the pattern.
The following script provides you some good pattern matching examples:
SELECT CASE WHEN 'FYICenter.com' LIKE '%Center%'
THEN 'TRUE' ELSE 'FALSE' END FROM DUAL;
TRUE
SELECT CASE WHEN 'FYICenter.com' LIKE '%CENTER%'
THEN 'TRUE' ELSE 'FALSE' END FROM DUAL;
-- Case sensitive by default
FALSE
SELECT CASE WHEN 'FYICenter.com' LIKE '%Center_com'
THEN 'TRUE' ELSE 'FALSE' END FROM DUAL;
TRUE
SELECT CASE WHEN '100% correct' LIKE '100\% %' ESCAPE '\'
THEN 'TRUE' ELSE 'FALSE' END FROM DUAL;
TRUE

Micheal
Admin

Posts : 243
Join date : 2010-01-10

http://sql-tutorial.co.cc

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum