create table tab_test
(
t_id number(5) primary key,
t_name varchar2(100) not null,
t_sex varchar2(5),
constraint t_sex check(t_sex='男' or t_sex='女'),
t_cj number(20) not null,
t_date Date
)
create table tab_test1(
t1_id number(5) primary key,
t_id number(5),
constraint pk_test_id foreign key (t_id) references tab_test(t_id)
)
create sequence tex_id
start with 1
increment by 1
select *from tab_test
insert into tab_test values(tex_id.nextval,'王青山','女',22,'14-4月-1997')
insert into tab_test
select 11,'顾坤伦','男','18-3月-1998' from dual union
select 12,'白银龙','男','18-3月-1998' from dual union
select 13,'冯荒芜','男','18-3月-1998' from dual
create table tab_test1 as select * from tab_test
insert into tab_test1 select from tab_test
select * from tab_test1
select table tab_test1 from tab_test
update tab_test set t_name='徐兵兵',t_sex='女' where t_id=6
delete from tab_test where t_name='徐兵兵' and t_sex='女'
delete from tab_test where t_name='徐兵兵' or t_sex='女'
truncate table tab_test1
select * from tab_test where t_cj = (select max(t_cj)from tab_test)
select t_name,t_id from tab_test where t_cj = (select max(t_cj)from tab_test)
select * from tab_test where t_cj>=all (select t_cj from tab_test where t_name='白银龙')
select t_cj from tab_test where t_cj>=all (select t_cj from tab_test where t_name='白银龙')
select * from tab_test a where 60 <(select t_cj from tab_test b where a.t_id=b.t_id)
select e.* from (select rownum r,t_id,t_name,t_sex,t_cj,t_date from tab_test) e where r>=1 and r<=6yy
select * from emp
select *from emp where sal =(select max(sal) from emp)
select * from emp where sal>(select max(sal) from emp where deptno=30)
select * from emp where sal>all(select sal from emp where deptno=30)
select b.* from emp b join
(select deptno,min(sal) as minsal from emp group by deptno) a on a.deptno=b.deptno and b.sal=a.minsal
select * from emp where (deptno,sal) in (select deptno,min(sal) as minsal from emp group by deptno)
select * from emp a where exists (select * from emp b where a.empno=b.mgr)
select 字段1,字段2 from 表1,表2 where 表1.字段 = 表2.字段 and 条件
select 字段1,字段2 from 表1 join 表2 on 表1.字段 = 表2.字段 where 条件
select * from (select * from <table> order by <key>) where rownum=1;
select * from (select * from <table> order by <key> desc) where rownum=1;