You learned that 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.
PL/SQL is not case sensitive, so lower-case letters are equivalent to corresponding upper-case letters except within string and character literals. In the given below example you see how we can combine these operators: Example:
SQL> -- create demo table
SQL> create table Student(
2 ID VARCHAR2(4 BYTE) NOT NULL,
3 First_Name VARCHAR2(10 BYTE),
4 Last_Name VARCHAR2(10 BYTE),
5 DOB DATE,
6 Fees Number(8,2),
7 City VARCHAR2(10 BYTE),
8 Field VARCHAR2(15 BYTE)
9 )
10 / Table created. SQL>
SQL> -- prepare data
SQL> insert into Student(ID, First_Name, Last_Name, DOB, End_Date, Fees, City, Field)
2 values ('01','Jason', 'Martin', to_date('19960725','YYYYMMDD'), to_date('20060725','YYYYMMDD'), 1234.56, 'Toronto', 'Programmer')
3 / 1 row created. SQL> insert into Student(ID, First_Name, Last_Name, DOB, End_Date, Fees, City, Field)
2 values('02','Alison', 'Mathews', to_date('19760321','YYYYMMDD'), to_date('19860221','YYYYMMDD'), 6661.78, 'Vancouver','Tester')
3 / 1 row created. SQL> insert into Student(ID, First_Name, Last_Name, DOB, End_Date, Fees, City, Field)
2 values('03','James', 'Smith', to_date('19781212','YYYYMMDD'), to_date('19900315','YYYYMMDD'), 6544.78, 'Vancouver','Tester')
3 / 1 row created. SQL> insert into Student(ID, First_Name, Last_Name, DOB, End_Date, Fees, City, Field)
2 values('04','Celia', 'Rice', to_date('19821024','YYYYMMDD'), to_date('19990421','YYYYMMDD'), 2344.78, 'Vancouver','Manager')
3 / 1 row created. SQL> insert into Student(ID, First_Name, Last_Name, DOB, End_Date, Fees, City, Field)
2 values('05','Robert', 'Black', to_date('19840115','YYYYMMDD'), to_date('19980808','YYYYMMDD'), 2334.78, 'Vancouver','Tester')
3 / 1 row created.
SQL>
SQL>
SQL>
SQL> -- display data in the table
SQL> select * from Student
2 /
ID FIRST_NAME LAST_NAME DOB Fees CITY Field
---- -------------- -------------- ----------- --------- -------- ----------
01 Harsh Gupta 25-JUL-06 1234.56 Toronto Programmer
02 Joliy Pera 21-FEB-86 6661.78 Vancouver Tester
03 Cutter Selmon 15-MAR-90 6544.78 Vancouver Tester
04 Brad tom 21-APR-99 2344.78 Vancouver Manager
05 Noman Javk 08-AUG-98 2334.78 Vancouver Tester 5 rows selected. SQL>
SQL>
SQL> SELECT * FROM Student
2 WHERE UPPER(first_name) LIKE '%JA%';
ID FIRST_NAME LAST_NAME DOB Fees CITY Field
---- ---------- -------------- ------------ --------- -------- ----------
01 Harsh Gupta 25-JUL-06 1234.56 Toronto Programmer
03 Cutter Selmon 15-MAR-90 6544.78 Vancouver Tester
2 rows selected.


0 comments:
Post a Comment