视图和实体化视图

视图与实体化视图
1. 创建带约束的视图
    SQL> create or replace view emp_sal_view
    as select employee_id,first_name,last_name,salary from employee
    where salary>2000 
    with check option;

2. 创建只读视图
    SQL> create or replace view emp_sal_view
    as select employee_id,first_name,last_name,salary 
    from employee
    with read only;

3. 创建内嵌视图
    SQL> select dname,maxsal,minsal 
    from dept d,(select deptno,max(sal) MaxSal,min(sal) MinSal from emp group by deptno) ds 
    where ds.deptno=d.deptno;

    --工资排行前5位
    SQL> select rownum,empno,ename,sal 
    from (select empno,ename,sal from emp  order by sal desc) where rownum<=5;

    --工资排行5-10位
    SQL> select rownum,rn,empno,ename,sal from (select rownum rn,empno,ename,sal from (select empno,ename,sal from emp  order by sal desc)) where rn>=5 and rn<=10;

        ROWNUM         RN      EMPNO ENAME             SAL
    ---------- ---------- ---------- ---------- ----------
             1          5       7698 BLAKE            2850
             2          6       7782 CLARK            2450
             3          7       7499 ALLEN            1600
             4          8       7844 TURNER           1500
             5          9       7934 MILLER           1300
             6         10       7521 WARD             1250

    6 rows selected.

    SQL> 

 

 

 

 

 

 

 

 

 

 

posted @ 2020-03-10 16:28  vmsysjack  阅读(539)  评论(0编辑  收藏  举报