Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grant Select, Insert, Update to a Tablespace

I've got a lot of tables in a tablespace, nearly 100. I have to grant Select, Insert, Update privileges on all those tables to a user. Is it possible? When I write:

GRANT USE OF TABLESPACE MYTABLESPACE TO USERNAME

I get oracle error "invalid or missing privilege"

like image 697
Mikayil Abdullayev Avatar asked Jun 01 '11 08:06

Mikayil Abdullayev


2 Answers

USE OF TABLESPACE is not a documented option, where did you find that?

You can do this to allow a user to create objects in a tablespace:

alter user username quota [amount] on mytablespace;

To grant select, insert, update and delete on objects you have to run a separate grant command for each table:

grant select, insert, update, delete on mytable1 to username;
....
like image 192
Tony Andrews Avatar answered Oct 19 '22 23:10

Tony Andrews


Use the data dictionary view dba_tables (resp. all_tables, if you cannot access dba_tables):

declare
  l_SQL varchar2(4000);
begin
  for cur in (
    select * from dba_tables where tablespace_name = 'mytablespace')
  loop
    l_sql := 'grant select, insert, update on ' || cur.owner || '.' || cur.table_name || ' to myuser';
    --dbms_output.put_line(l_SQL || ';');
    execute immediate l_SQL;
  end loop;
end;

If you just want to generate a script, comment out the execute immediate and un-comment the dbms_output.

like image 42
Frank Schmitt Avatar answered Oct 20 '22 01:10

Frank Schmitt