Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Grant select on all tables of other user
Rene Nyffenegger wrote:
>>>OK, but this is not what I would like to do. This way you have to specify >>>grants for each table. If a new table is added, a new SELECT grant has to be >>>given. Would it be possible to give this grants automatically each time a >>>new table is added ? >>> >>> >> >>You can do this using a schema trigger. >>If you want to see an example code of schema triggers ... try: >>http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:1380003556171 >> >>Anurag
Rene,
Something like this might work (as tested briefly by myself). I hope it does not wrap:
CREATE OR REPLACE package grantpkg
AS
procedure sel (in_obj in varchar2, in_user in varchar2);
end grantpkg;
/
show errors
CREATE OR REPLACE package body grantpkg
AS
procedure sel (in_obj in varchar2, in_user in varchar2)
is
begin
execute immediate 'grant select on '||in_obj||' to '||in_user;
end sel;
end grantpkg;
/
show errors
create or replace trigger trg_grant
after create on schema
declare
l_sysevent varchar(25);
v_jobno number;
begin
select ora_sysevent into l_sysevent from dual;
if ( l_sysevent = 'CREATE' )
then
dbms_job.submit(v_jobno, 'begin grantpkg.sel( '''|| ora_dict_obj_name ||''', ''TEMPUSER''); end;',sysdate);end if;
create table crtab (a number);
insert into crtab values (1);
commit;
Thanks,
Anurag
Received on Sat Apr 02 2005 - 14:05:01 CST