Select Statement
__________________________________________________________
#建表
create table lhj02(
id number(4),
name varchar2(10),
age number(3),
address varchar2(10),
birthday date);
#插入数据
insert into lhj02 values(1,'lhj',22,'bj',sysdate);
insert into lhj02 values(2,'myp',18,'sjz',sysdate);
insert into lhj02 values(3,'zx',19,'sh',sysdate);
insert into lhj02 values(4,'khx',21,'cd',sysdate);
insert into lhj02 values(5,'scx',16,'hn',sysdate);
insert into lhj02 values(6,'xhj',20,'hb',sysdate);
insert into lhj02 values(7,'ltl',22,'sx',sysdate);
#更新数据
update lhj02 set age=19 where id=2;
update lhj02 set id=9 where name='sd';
===================================================================
where
select * from lhj02 where age between 18 and 20;
select * from lhj02 where age>18 and age<=20;
select * from lhj02 where age in(18,20);
select * from lhj02 where age=18 or age=20;
==================================================================
like
select * from lhj02 where name like '%l%';
insert into lhj02 values(7,'ltl_d',22,'sx',sysdate);
insert into lhj02 values(7,'sd',22,'sx',sysdate);
select * from lhj02 where name like '_d';
select * from lhj02 where name like '%\_d%' escape '\';
==================================================================
null
insert into lhj02(id,name,age,birthday) values(8,'zhs',40,sysdate);
select * from lhj02 where address is null;
=================================================================
not
select * from lhj02 where age not between 19 and 21;
select * from lhj02 where age not in(19,22);
select * from lhj02 where address is not null;
=================================================================
多条件查询
SQL> select * from lhj02;
ID NAME AGE ADDRESS BIRTHDAY
---------- ---------- ---------- ---------- ---------
1 lhj 18 bj 22-SEP-08
2 myp 19 sjz 22-SEP-08
3 zx 20 sh 22-SEP-08
4 khx 18 cd 22-SEP-08
5 scx 22 hn 22-SEP-08
6 xhj 30 hb 22-SEP-08
7 ltl 22 sx 22-SEP-08
7 ltl_d 22 sx 22-SEP-08
9 sd 22 sx 22-SEP-08
8 zhs 40 22-SEP-08
10 rows selected.
<1>select * from lhj02 where age>22 and address='bj' or address='sx';
ID NAME AGE ADDRESS BIRTHDAY
---------- ---------- ---------- ---------- ---------
7 ltl 22