开发者

how to grant user privilege on specific schema? [duplicate]

开发者 https://www.devze.com 2023-03-25 08:07 出处:网络
This question already has answers here: Grant Select on all Tables Owned By Specific User (5 answers) Closed 5 years ago.
This question already has answers here: Grant Select on all Tables Owned By Specific User (5 answers) Closed 5 years ago.

The situation is I have two schemas: A and B. I have a restricted user that I need to give a privilege do SELECT开发者_运维技巧 queries in B schema and just it. How can I grant this user?


You can't.

The best you can do is grant user a 'select' privilege each table in schema b.

this query will generate the commands you'll need:

select 'grant select on A.'||table_name||' to B;' 
from dba_Tables 
where owner = 'A';

The problem with this, is in the case you will want to add new table to A. then you'll have to grant the privilege on it separately. it will not do it automatically..


You may find you do not have access to dba_tables, The following block of code run in the owning schema (a) will grant permissions to all tables, to the user b

BEGIN
    FOR t IN (SELECT * FROM user_tables) 
    LOOP   
        EXECUTE IMMEDIATE 'GRANT SELECT ON ' || t.table_name || ' TO b';    
    END LOOP;
END;
0

精彩评论

暂无评论...
验证码 换一张
取 消