devxlogo

Use of LIKE in SQL

Use of LIKE in SQL

The LIKE statement is often used in SQL queries with wildcards to find data that issimilar to a matching pattern. PL/SQL has two forms of wildcard: _ and %.

The “_” matches a single character, while “%” matches n number of characters. The _ is faster than % because only one character needs to be evaluated; “%” must perform look-ahead parsing. “_” also works a little differently than “%” because it requires that a match exist, whereas “%” does not have this requirement.

Consider the following statement:

 select * from table_name where 'JAMES' like 'Jame_';

This will match; but you won’t get a match with the following:

 select * from table_name where 'Jane' like 'Jane_';

You would, however, get a match if the previous statement was written as follows:

 select * from table_name where 'Jane' like 'Jane%';

There is a tendency to use “%” with all LIKE statements. When the exact number of characters to be matched is known, it is more efficient to use “_”.

See also  Why ChatGPT Is So Important Today
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist