Pages

Monday, 28 March 2011

Effectively Using/Work with LIKE Operator in PL/SQL Asp.Net C#


The LIKE operator is used in character string comparisons with pattern matching it compares a character, string, or CLOB value to a pattern and returns TRUE if the value matches the pattern and FALSE if it does not. The pattern can include the two "wildcard" characters underscore (_) and percent sign (%). It allows you to use wildcards in the where clause of an PL/SQL statement. This allows you to perform pattern matching. The LIKE condition can be used in any valid SQL statement - select, insert, update, or delete. Underscore matches exactly one character. Percent sign (%) matches zero or more characters. The syntax for a condition using the LIKE operator is shown in this diagram:


like.gif

Example:
SQL> create table Worker(
2    Worker_ID                  VARCHAR2(4 BYTE)         NOT NULL,
3    Worker_Name              VARCHAR2(10 BYTE),
4    Joining_Date               DATE,
5    Salary                        Number(8,2),
6    City                           VARCHAR2(10 BYTE),
7    Designation                 VARCHAR2(15 BYTE)
8  )
9  /
Table created.
SQL>
SQL> -- prepare data
SQL> insert into Worker(Worker_ID,  Worker_Name,       Joining_Date,                       Salary,  City,       Designation)
2               values ('01','Jason',  , to_date('20060725','YYYYMMDD'), 1234.56, 'NY',  'TL')
3  /
1 row created.
SQL> insert into Worker(Worker_ID,  Worker_Name,       Joining_Date,                       Salary,  City,       Designation)
2                values('02','Black',   to_date('19760321','YYYYMMDD'),, 6661.78, 'Torr.','Executive')
3  /
1 row created.
SQL> insert into Worker(Worker_ID,  Worker_Name,       Joining_Date,                       Salary,  City,       Designation)
2                values('03','Mathews',  to_date('19900315','YYYYMMDD'), 6544.78, 'Torr.','Executive')
3  /
1 row created.
SQL> insert into Worker(Worker_ID,  Worker_Name,      Joining_Date,                       Salary,  City,       Designation)
2                values('04','Green',  to_date('19821024','YYYYMMDD'), , 2344.78, 'Torr.','Manager')
3  /
1 row created.
SQL> insert into Worker(Worker_ID,  Worker_Name,      Joining_Date,                       Salary,  City,       Designation)
2                values('05','Albert', to_date('19980808','YYYYMMDD'), 2334.78, 'Torr.','Executive')
3  /
1 row created.
SQL> insert into Worker(Worker_ID,  Worker_Name,      Joining_Date,                       Salary, City,        Designation)
2                values('06','Roma',   to_date('19870730','YYYYMMDD'), , 4322.78,'Van.',  'Executive')
3  /
1 row created.
SQL>
SQL> -- display data in the table
SQL> select * from Worker
2  /
Worker_ID      Worker_Name     Joining_Date        Salary      City      Designation
------------   ---------------   -------------    ----------   ------  ---------------
01                Jason            25-JUL-06        1234.56      NY        TL
02                 Black            21-MAR-76       6661.78      Torr.      Executive
03                 Mathews       15-MAR-90       6544.78      Torr.      Executive
04                 Green           24-OCT-82       2344.78      Torr.      Manager
05                 Albert           08-AUG-98       2334.78      Torr.      Executive
06                 Roma            30-JUL-87        4322.78      Van.       Executive
6 rows selected.
SQL>
SQL>
SQL>
SQL> SELECT * FROM Worker WHERE Worker_Name LIKE '_o%';
Worker_ID      Worker_Name     Joining_Date      Salary       City        Designation
-----------   ----------------  -------------    ----------  -------   ------------
05               Albert         08-AUG-98        2334.78      Torr.       Executive

0 comments:

Post a Comment

 
Powered by Blogger