Friday, June 1, 2012

Like operator in SOQL


Like operator in SOQL
    Like keyword is same as like in SQL. We can find/get the record using this keyword. Expression is true if the value in the specified fieldname matches characters of text string in the specified value.
    The LIKE operator in SOQL and SOSL is similar to the LIKE operator in SQL; it provides a mechanism for matching partial text strings and includes support for wildcards.
    * % and _ wildcards are supported for LIKE operator.
    * % wildcard matches zero or more characters.
    * _ wildcard matches exactly one character.
    * Text string in the specified value must be enclosed in single quotes.
    * LIKE operator is supported for string fields only.
    * LIKE operator performs a case-insensitive match, unlike the case-sensitive matching in SQL.
    * LIKE operator in SOQL and SOSL supports escaping of special characters % or _.
    * Do not use the backslash character in a search except to escape a character.

SOQL using like:

1. SELECT AccountId, FirstName, lastname FROM Contact WHERE lastname LIKE 'AC_%'

2. Select id, email from contact where email like '%a' or email like '%x';

No comments:

Post a Comment