【sql语句】实验二 视图

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_40307434/article/details/84311560

1. 根据EMPLOYEES表中的雇员编号、雇员名字、部门编号创建一个名为EMPLOYEES_VU的视图。把雇员名字的表头改为EMPLOYEE。

create view employees_vu
as select employee_id, last_name employee, department_id
from employees;

2. 显示EMPLOYEES_VU视图的内容。

select *from employees_vu;

3. 从USER_VIEWS数据字典视图中选择视图的名字和文本。
EMP_DETAILS_VIEW作为你的模式的一部分已被创建。
注意:为了看到一个LONG列的更多内容,可以使用iSQL*Plus中SET LONG n命令,这里n的值就是你想看到的LONG列的字符的数目。

set long 880;//normal:80
select view_name,text from user_views
where view_name='EMPLOYEES_VU' or view_name='EMP_DETAILS_VIEW';

4. 使用EMPLOYEES_VU视图,输入一个查询显示所有雇员的名字和部门号。
select employee,department_id from employees_vu;

5. 建立一个名为DEPT50的视图,其中包含在50部门中所有雇员的雇员号、雇员名和部门编号,标识视图列为EMPNO, EMPLOYEE和 DEPTNO。不能允许通过视图将一个雇员再分配到另一个部门。

create view dept50
as select employee_id empno,last_name employee,department_id deptno
from employees
where department_id=50
with check option;

6. 显示DEPT50视图的结构和内容

describe dept50;
select *from dept50;

7. 试图把Matos调派到部门80中去。

//视图 WITH CHECK OPTION where 子句违规
update dept50
set deptno=80
where employee='Matos';

8.建立名为SALARY_VU的视图,其中包含所有雇员的名、部门名字、薪水和薪水等级。分别用Employee、Department、 Salary 和 Grade标识各列。(在scott/tiger用户下做本题,使用emp、dept、salgrade(薪水等级)三张表)

emp(EMPNO, ENAME, JOB, MGR HIREDATE, SAL, COMM, DEPTNO )
dept(DEPTNO, DNAME, LOC )
salgrade(GRADE, LOSAL, HISAL )

grant create view to scott;//scott无权,用system登录授权

create view salary_vu
as select ename employee, dname department,sal salary,grade
from emp,dept,salgrade
where emp.deptno=dept.deptno and emp.sal between salgrade.losal and salgrade.hisal;

猜你喜欢

转载自blog.csdn.net/qq_40307434/article/details/84311560
今日推荐