Oracle Like Condition
The LIKE condition allows you to use wildcards in the where clause of an 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.
The patterns that you can choose from are.
% allows you to match any string of any length (including zero length).
_ allows you to match on a single character.
Some related examples.
1. Like with '__' (Any two characters).
SQL> select * from Employee 2 WHERE First_Name LIKE'A____n'; ID FIRST_NAME LAST_NAME START_DAT END_DATE SALARY CITY ---- ---------- ---------- --------- --------- ---------- --------- 02 Alison Mathews 21-MAR-76 21-FEB-86 6661.78 Vancouver
2. Like with '_' and '%'.
SQL> SELECT First_Name 2 FROM Employee 3 WHERE First_Name LIKE'_e%'; FIRST_NAME ---------- Celia
3. Use two '%' in Like statement.
SQL> SELECT First_Name 2 FROM Employee 3 WHERE First_Name LIKE'%a%'; FIRST_NAME ---------- Jason James Celia Linda David James 6 rows selected.
4. Using a NOT operator with like.
SQL> SELECT ID, First_Name, Last_Name 2 FROM Employee 3 WHERE City NOT LIKE'%Van%'; ID FIRST_NAME LAST_NAME ---- ---------- ---------- 01 Jason Martin 06 Linda Green 07 David Larry
5. Use % in word ending.
SQL> SELECT * FROM product WHERE product_name LIKE 'Chrome%'; no rows selected
No comments:
Post a Comment