对表的操作

--选取整个表的列
select * from emp;
--选取指定列的内容
select job from emp;
select ename,sal from emp;
--条件判断
select sal from emp
where sal=800;
--between and 方法
select * from emp
where sal between 2000 and 3000;
--嵌套的使用
select job from
(select * from emp
where sal between 2000 and 3000);
--单列数据的改变
select sal+25 from emp;
--用like(模糊)概念 (-一个字符) (% 0个或多个字符)
select job from emp
where job like '%LE%';
--从in()里面的数据选出
select * from emp
where comm in(300,500);
select sal,sal+25.00 AS saly from emp;
--字符串的连接 AS别名 将job换成ta
select empno,empno+25||'is a '||job AS ta from emp;
--删除重复行 关键词DISTINCT
select DISTINCT comm from emp;
--用IS NULL 关键字判断为空的情况
select * from emp
where comm IS NULL;
select comm from emp
where comm IS NULL;

--使用join on 创建多表连接 on后面跟两个表的关联条件

select * from emp e join dept d on e.deptno=d.deptno order by empno;
--使用左外连接 右外连接 满外连接
select * from emp e full join dept d on e.deptno=d.deptno order by empno;
--
create table wan1 (name varchar2(5) not null,age number(3) not null,sal number(5),time1 date);

insert into wan1 values ('ygu' ,25,4000,sysdate);
insert into wan1 values ('drt' ,22,5000,sysdate);
insert into wan values ('dsf ' ,26,6000,sysdate);
insert into wan (name,sal) values ('ere' ,7000) ;

update wan set age=30,time1=sysdate where name='ere';

select * from wan where sal<=6000;
select to_char(time1) from wan;
select to_date(time1) from wan;
select to_number(time1) from wan;

select * from wan1;
--清空表数据 和delete 效果一样
truncate table wan1;
insert into wan1 values ('rgr',5,2,default)
drop table wan1;


--将日期也可以数字化来使用
select * from wan where (select to_char(time1,'yyyymmdd') from wan where name='ere' ) between 2017-07-16 and 2017-07-19;
--复制表 此时的values 可以省略
insert into wan (name,sal) select job,sal from emp where ename='SMITH'
--使用默认值 sysdate获取的是天数
update wan set age=35,time1=sysdate-10 where sal=800;
--重命名表
rename wan to wan3;
select * from wan3;

 

 














 

posted on 2017-07-26 19:24  -薛凯-  阅读(337)  评论(0编辑  收藏  举报

导航