需求:要求A用户可以访问B用户中某张表中的部分字段,且可以更新B用户中指定的字段。
如:HR用户可以访问scott.dept中的deptno,dname 列,但只能更新dname列。
SQL> conn scott/tiger
已连接。
SQL> GRANT SELECT ON DEPT TO hr;
授权成功。
SQL> GRANT update (dname) ON DEPT TO hr;
授权成功。
SQL> conn hr/hr
已连接。
SQL> create or replace view update_dname as
2 (select deptno ,dname from scott.dept);
视图已创建。
SQL> select * from update_dname;
DEPTNO DNAME
------ -----------
31 CODE
32 CODE
10 ACCOUNTING
20 RESEARCH
30 SALES
40 OPERATIONS
11 CODE
已选择7行。
SQL> update update_dname set dname='code1' where deptno=31;
已更新 1 行。
SQL> commit;
提交完成。
-- 由于没有赋予hr用户更新scott.deptno的权限,在更新时报错。
SQL> update update_dname set deptno=131 where deptno=31;
update update_dname set deptno=131 where deptno=31
*
第 1 行出现错误:
ORA-01031: 权限不足
SQL>