Oracle 简单操作手册

来源:互联网 发布:jquery 数组 json 编辑:程序博客网 时间:2024/06/01 08:37
  • 登录sqlplus

    命令提示符(CMD) sqlplus username/password
    或者 sqlplus username/password@ORCL(显式登录)

    切换登录 conn username/password as sysdba

  • SQL详解

    1. DDL:定义和管理数据库的语言
    2. DML:数据操作语言
      select * from emp
      insert into emp into values(?,?,?)
      update emp set name=’aa’ where id =1
      delete from emp where id=1

      • 连接查询

        • 外连接

          1. 左外连接(显示左表中不满足条件的记录也会显示)

            select * from emp left outer join dept on EMP.DEPTNO=DEPT.DEPTNO  
          2. 右外连接(显示右表中不满足条件的记录也会显示)

            select * from emp right outer join dept on EMP.DEPTNO=DEPT.DEPTNO
          3. 全外连接

            select * from emp full  outer join dept on EMP.DEPTNO=DEPT.DEPTNO 
      • 内连接

        select * from emp inner join dept on EMP.DEPTNO=DEPT.DEPTNO 
      • 自连接

        select * from emp where sal >( select sal from emp where ='大S'select e1.* from emp e1 ,emp e2 where e1.sal>e2.sal and e2.ename='大S'
    3. DCL:数据控制语言
  • 案例

     select * from     (select empno,deptno,sal,dense_rank()over (partition by deptno order by sal desc) r from emp)    where r<=2;

    其中:over为分析函数,分析函数用于计算基于组的某种聚合值,它和聚合函数的不同之处 是对于每个组返回多行,而聚合函数对于每个组只返回一行

    dense_rank()是连续排序,有两个第二名时仍然跟着第三名

    partition by …..只参照….排序,可以在各个分组内从1开时排序

0 0