Oracle数据库创建只读用户
创建一个只读用户user2,只能查询管理员用户user1下的表,不能增删改。
操作环境:PL/SQL Developer
1、用管理员用户user1登录,创建用户user2、并授权
--创建用户user1,密码123456 create user user2 identified by 123456; --授权 grant connect to user2; grant create synonym to user2; grant create session to user2;
2、授予user2的查询表权限:复制下面的查询结果,执行
select 'grant select on '||owner||'.'||object_name||' to user2;' from dba_objects where owner in ('USER1') and object_type in ('VIEW','PROCEDURE','TABLE','FUNCTION');
3、为user2创建同义词:复制下面的查询结果,执行
select 'create or replace SYNONYM user2.' || object_name|| ' FOR ' || owner || '.' || object_name|| ';' from dba_objects where owner in ('USER1') and object_type in ('VIEW','PROCEDURE','TABLE','FUNCTION');
测试:
用user2登录数据库,查询正常,增删改提示没有权限。