Page 198 - DCAP310_INTRODUCTION_TO_ARTIFICIAL_INTELLIGENCE_AND_EXPERT_SYSTEMS
P. 198
Introduction to Artificial Intelligence & Expert Systems
Notes This condition is true for these last_name values:
SMITHE, SMITHY, SMITHS
This condition is false for SMITH because the special underscore character (_) must match exactly
one character of the last_name value.
ESCAPE Clause Example
The following example searches for employees with the pattern A_B in their name:
SELECT last_name
FROM employees
WHERE last_name LIKE ‘%A\_B%’ ESCAPE ‘\’;
The ESCAPE clause identifies the backslash (\) as the escape character. In the pattern, the escape
character precedes the underscore (_). This causes Oracle to interpret the underscore literally,
rather than as a special pattern matching character.
Patterns Without % Example
If a pattern does not contain the % character, then the condition can be true only if both operands
have the same length. Consider the definition of this table and the values inserted into it:
CREATE TABLE ducks (f CHAR(6), v VARCHAR2(6));
INSERT INTO ducks VALUES (‘DUCK’, ‘DUCK’);
SELECT ‘*’||f||’*’ “char”,
‘*’||v||’*’ “varchar”
FROM ducks;
char varchar
——– ——–
*DUCK * *DUCK*
In many pattern, many object pattern matching, a collection of patterns is compared to a collection
of objects, and all the matches are determined. That is, the pattern matcher finds every object that
matches each pattern. This kind of pattern matching is used extensively in Artificial Intelligence
programs today. For instance, it is a basic component of production system interpreters. The
interpreters use it to determine which productions have satisfied condition parts. Unfortunately,
it can be slow when large numbers of patterns or objects are involved. Some systems have been
observed to spend more than nine-tenths of their total run time performing this kind of pattern
matching. The simplest patterns contain only constant symbols and numbers. A pattern containing
only constants matches a working memory element if every constant in the pattern occurs in the
corresponding position in the working memory element.
We have seen SQL SELECT command to fetch data from MySQL table. We can also use a
conditional clause called WHERE clause to select required records.
A WHERE clause with equal sign (=) works fine where we want to do an exact match. Like if
“tutorial_author = ‘Sanjay’”. But there may be a requirement where we want to filter out all the
results where tutorial_author name should contain “jay”. This can be handled using SQL LIKE
clause alongwith WHERE clause.
If SQL LIKE clause is used along with % characters then it will work like a meta character (*) in
Unix while listing out all the files or directories at command prompt.
Without a % character LIKE clause is very similar to equal sign alongwith WHERE clause.
192 LOVELY PROFESSIONAL UNIVERSITY