数据库之视图
1、以一个具体需求展开:
跨用户访问另外一个 用户的表?希望得到雇员的全部信息和部门名称?但是hr用户不希望把薪水这一列提供给scott用户?
----视图:
----在管理员账户sys下给scott授权查询hr账户相应表的权限
grant select on hr.departments to scott;
grant select on hr.employees to scott;
---在hr账户下实现跨用户访问scott里面的表:用户名.表名,前提是要授权
select *from hr.employees s;
select *from hr.departments t;
---实现跨库访问:用户名.表名@数据库链接
---在管理员账户sys下收回权限
revoke select on hr.departments from scott;
revoke select on hr.employees from scott;
---在hr下创建一个视图给scott用户,不能给基础表
create or replace view view_employees as
select
s.employee_id,
s.first_name,
s.email,
s.phone_number,
s.hire_date,
s.job_id,
s.department_id,
t.department_name
from employees s
left join departments t
on s.department_id=t.department_id
with read only
select *from view_employees;
---在管理员账户sys下给scott授权查询hr里面视图view_employees的权限
grant select on hr.view_employees to scott;
---在scott下
select *from hr.view_employees;
还没有评论,来说两句吧...