%Like meta-SQL element
Syntax
%Like("Literal")
Description
The %Like construct expands to look for literal values. This meta-SQL should be used when looking for like values. A percent sign character (%) is appended to literal.
Note:
This meta-SQL is not implemented for COBOL.
If you're using a bind marker (such as ":1") for the literal argument in a SQLExec, you must wrap the SQL string with the ExpandSqlBinds function. ExpandSqlBinds replaces bind markers with the actual input values.
%Like generates the following:
like 'literal%'
If the literal value contains a backslash character (\) or percent sign (%), then %Like generates the following:
like 'literal%' escape '\'
Parameters
| Parameter | Description |
|---|---|
|
literal |
Specify the value to search for. |
Using %Like and Eliminating Blanks
Some platforms require that you use RTRIM to get the correct value. The following characters are wildcards even when preceded with the backslash (\) escape character:
-
%
-
_
Therefore, on some platforms, the literal must end with a percent sign (%) wildcard that isn't preceded by a backslash (\). Here are some examples:
-
literal = 'ABC%'There is no need for RTRIM on any platform.
-
literal = 'ABC\%'You need RTRIM on Microsoft SQL Server and DB2.
Using %Like and Trailing Blanks
Not all executions of %Like perform the same. When dealing with trailing blanks, some platforms behave as if there is an implicit percent sign (%) at the end of the comparison string, while most do not.
In the following example, if the selected column contains the string "ABCD " (with three trailing blanks. The statement may or may not return any rows:
select * from t1 Where c like 'ABCD'
Therefore, it is always important to explicitly code the percent sign (%) the end of matching strings for columns where you want to include trailing blanks. The following table shows the use of implicit percent signs with specific databases:
| Database | Includes Implicit Percent Sign (%) |
|---|---|
|
PeopleSoft Standard Usage |
Yes |
|
DB2/400 |
No |
|
DB2/MVS |
No |
|
DB2/Unix |
No |
|
Microsoft SQL Server |
Yes |
|
Oracle |
No |
|
SQLBase |
No |
Using %Like and Wildcards
SQL specifies two wildcards that can be used when specifying pattern matching strings for use with the SQL Like predicate. The underscore is used as a substitution for a single character within a string, and the percent sign represents any number of character spaces within a string. All supported databases use these characters as wildcards.