oracle
站在牛顿肩膀上等苹果
这个作者很懒,什么都没留下…
展开
-
整理oracle数据库的事务
--事务处理--增删改都要开启事务,事务必须提交我们的数据才会在数据库中变更--commit; 执行后会 提交事务delete from myemp t where t.empno= 7788;select * from myemp--事务在没有提交之前都可以回滚(让之前的删除操作失效),提交之后没有办法回滚--rollback 回滚--update 锁的概念--举例select * from myemp for update;--执行这条语句时,在没有提交事务之...原创 2020-06-22 08:18:12 · 123 阅读 · 0 评论 -
union 和unionall以及oracle的增删改
--union 把两个集合做并集时 会把重复的数据去掉select * from emp where sal>1000unionselect * from emp where sal >2000;-- union all 把两个并集合并时 是 不去重的select * from emp where sal>1000union allselect * from emp where sal >2000;--合并时 要合并的列 类型必须一致,列的...原创 2020-06-20 09:11:41 · 560 阅读 · 0 评论 -
整理oracle子查询
--查询工资比员工编号为7654高的员工select sal from emp e where e.empno=7654; --查出员工编号为7654高的员工的工资--调用子查询select * from emp twhere t.sal > (select sal from emp e where e.empno = 7654);/*子查询有三种所有的子查询必须在()中1、单列子查询,返回结果时一个列的内容2、单行子查询 返回多个列,有可能是一个完整的记录3、多行子查询,...原创 2020-06-20 09:09:44 · 207 阅读 · 0 评论 -
分组统计限定查询和exits子查询关联外侧
分组统计限定查询/*总结在分组统计时,除了分组函数以外,结果列必须是group by 分组的列(后边有的列,前边才能有,后边没有的,前边一定不能有)*/-- having 在group by后边,作用在分组函数上每个部门的职位数大于1的select count(*), deptno, job from emp group by deptno,job having count(*)>1;select count(*) ,avg(sal) ,deptno from emp group by原创 2020-06-20 09:09:02 · 183 阅读 · 0 评论 -
分组函数和分组统计
分组函数:select count(empno) from emp; --查询有多少条记录/数据select min(sal) from emp; --当前列的最低工资select max(sal) from emp; --当前最高工资select sum(sal) from emp e where e.deptno = 20; --20部门的总工资分组统计:- 通过部门分组,并显示每组人数和部门select count(empno), deptno from emp ...原创 2020-06-20 09:06:44 · 245 阅读 · 0 评论 -
整理外连接
--查询每一个员工的部门 --两张表做关联查询时,其中一张表要查询全量的数据,并且不会因为另一张表的关联而被筛选掉 --在两张表关联的时候,非全量表的关联字段后面加上 “(+)” 就可以做外连接查询 select * from dept d,emp e where d.deptno = e.deptno(+); select * from dept -...原创 2020-06-20 08:50:08 · 122 阅读 · 0 评论 -
整理多表联合查询
--两张表联合查询select * from emp e, dept d where e.deptno = d.deptno ; --寻找两张表的关联处,也就是都有deptno使之相等select e.empno, e.ename , d.deptno, d.dname, d.loc from emp e, dept d where e.deptno = d.deptno; --按照给定的列显示 --查询员工的上级领导 自己关联自己 sele...原创 2020-06-20 08:49:15 · 215 阅读 · 0 评论 -
整理通用函数
--空加上任意数都为空select * from emp;--想要计算员工的年薪加上奖金所得的钱数select sal * 12 + comm from emp; --这样的话有奖金的才能显示,没有奖金的总钱数为0--nvl 函数select ename, (sal * 12 + nvl(comm, 0) )yearsal from emp; --把空变为0就可以计算了。--decode函数 类似if--elseselect decode(1, 1, '我是1', 2, '我是2', '.原创 2020-06-20 08:48:16 · 148 阅读 · 0 评论 -
日期和转换函数
日期:select sysdate from dual; --查询当前日期select hiredate from emp;select (sysdate-hiredate)/7 from emp; --查询员工工作的周数,用当前日期减去入职日期,除以7select ename,trunc((sysdate-hiredate)/7 )from emp; --查询员工工作的整周数select ename, months_between(sysdate,hiredate) from ...原创 2020-06-20 08:47:38 · 316 阅读 · 0 评论 -
排序和单行函数
排序select * from emp order by sal desc; -- 工资倒序select * from emp order by sal ; --默认正序select * from emp order by sal desc,hiredate desc; --工资和入职日期倒序select *from emp;单行函数select 1 from dual; --dual是伪表select upper('smith') from dual; --把小写字...原创 2020-06-20 08:46:00 · 105 阅读 · 0 评论 -
简单查询和限定查询
简单查询:select * from emp;select job from emp;select empno as 员工编号 ,ename as 员工姓名 from emp;select empno eno,ename eme from emp;--常用注释select distinct job from emp;select distinct ename nam, job jo ,deptno deno from emp; --只有所在行全部相同才能被认为相同,可以合并selec...原创 2020-06-20 08:44:06 · 144 阅读 · 0 评论