Grant SELECT on multiple tables oracle

后端 未结 5 630
攒了一身酷
攒了一身酷 2020-12-11 00:37

I have 3 tables table1,table2,table3. I want to grant(select for example) these tables to a user, user1.

I know that I can grant with:

grant select          


        
相关标签:
5条回答
  • 2020-12-11 01:15

    You can do it with dynamic query, just run the following script in pl-sql or sqlplus:

    select 'grant select on user_name_owner.'||table_name|| 'to user_name1 ;' from dba_tables t where t.owner='user_name_owner'
    

    and then execute result.

    0 讨论(0)
  • 2020-12-11 01:18

    This worked for me on my Oracle database:

    SELECT   'GRANT SELECT, insert, update, delete ON mySchema.' || TABLE_NAME || ' to myUser;'
    FROM     user_tables
    where table_name like 'myTblPrefix%'
    

    Then, copy the results, paste them into your editor, then run them like a script.

    You could also write a script and use "Execute Immediate" to run the generated SQL if you don't want the extra copy/paste steps.

    0 讨论(0)
  • 2020-12-11 01:20

    No. As the documentation shows, you can only grant access to one object at a time.

    0 讨论(0)
  • 2020-12-11 01:20

    If you want to grant to both tables and views try:

    SELECT DISTINCT
        || OWNER
        || '.'
        || TABLE_NAME
        || ' to db_user;'
    FROM
        ALL_TAB_COLS 
    WHERE
        TABLE_NAME LIKE 'TABLE_NAME_%';
    

    For just views try:

    SELECT
        'grant select on '
        || OWNER
        || '.'
        || VIEW_NAME
        || ' to REPORT_DW;'
    FROM
        ALL_VIEWS
    WHERE
        VIEW_NAME LIKE 'VIEW_NAME_%';
    

    Copy results and execute.

    0 讨论(0)
  • 2020-12-11 01:32

    my suggestion is...create role in oracle using

    create role <role_name>;
    

    then assign privileges to that role using

    grant select on <table_name> to <role_name>;
    

    then assign that group of privileges via that role to any user by using

    grant  <role_name> to <user_name>...;
    
    0 讨论(0)
提交回复
热议问题