1:案例演示:
1:創建表
CREATE TABLE db_fruits
(
f_id varchar2(10) not null,
s_id number(6) not null,
f_name varchar(25) not null,
f_price number(8,2) not null
)
2:插入數據
---插入數據
insert into db_fruits values ('a1',101,'apple',5.2);
insert into db_fruits values ('b1',102,'blueberry',10.2);
insert into db_fruits values ('c1',103,'melon',4.3);
insert into db_fruits values ('bs1',104,'orange',11.2);
insert into db_fruits values ('bs2',105,'grape',7.2);
insert into db_fruits values ('bs3',106,'melon',5.3);
insert into db_fruits values ('bs4',107,'coconut',9.2);
insert into db_fruits values('bs5',108,'cherry',7.2);
insert into db_fruits values('bs6',109,'lemoon',10.3);
insert into db_fruits values('bs7',110,'blueberry',9.2);
insert into db_fruits values('bs8',111,'berry',7.2);
insert into db_fruits values('bs9',112,'chrry',10.3);
insert into db_fruits values('bs10',113,'chbby',23.3);
3:模糊查詢
1:通配符%
1:模糊查詢以B開頭的水果名稱,不管後面的字母是什麼
select * from db_fruits f where f.f_name like 'b%'
2:查詢f_name中包含b的記錄,只要水果名字帶b的都進行顯示
select * from db_fruits f where f.f_name like '%b%'
3:查詢水果中以c開頭,並且以y結尾的水果名稱
2:通配符_
下劃線通配符“_”,一次只能匹配任意一個字符,如果要匹配多個字符,需要使用相同個數的"_",列如,你想匹配水果名稱字符第2個開通的是e,就需要使用兩個"_",也就是"__"