-
Notifications
You must be signed in to change notification settings - Fork 1
/
grant_privs_to_apex_user.sql
54 lines (46 loc) · 1.48 KB
/
grant_privs_to_apex_user.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
set serveroutput on;
--grant table, view and package privileges to the apex user using a role
--first create a role for the grants using a sufficiently privileged user
--create role event_api_role;
--then grant the role to the apex user using a sufficiently privileged user
--grant event_api_role to obe;
declare
l_execute boolean := true;
l_user varchar2(30) := 'EVENT_API_ROLE';
cursor c_tables is
select table_name
from user_tables;
cursor c_views is
select object_name
from user_objects
where object_type = 'VIEW'
and object_name not like '%XML%'
and object_name not like '%JSON%';
cursor c_packages is
select object_name
from user_objects
where object_type = 'PACKAGE';
v_ddl varchar2(100);
begin
for r in c_tables loop
v_ddl := 'grant select, insert, update, delete on event_system.' || r.table_name || ' to ' || l_user;
dbms_output.put_line(v_ddl);
if l_execute then
execute immediate v_ddl;
end if;
end loop;
for r in c_views loop
v_ddl := 'grant select on event_system.' || r.object_name || ' to ' || l_user;
dbms_output.put_line(v_ddl);
if l_execute then
execute immediate v_ddl;
end if;
end loop;
for r in c_packages loop
v_ddl := 'grant execute on event_system.' || r.object_name || ' to ' || l_user;
dbms_output.put_line(v_ddl);
if l_execute then
execute immediate v_ddl;
end if;
end loop;
end;