Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2a9337b

Browse files
authored
Merge pull request #713 from Pazus/bugfix/check_object_grants
fix check_object_grants bug on all_tab_privs.
2 parents 91c4b13 + 4ee9e7c commit 2a9337b

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

source/check_object_grants.sql

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ declare
22
c_expected_grants constant dbmsoutput_linesarray := dbmsoutput_linesarray('DBMS_LOCK','DBMS_CRYPTO');
33

44
l_missing_grants varchar2(4000);
5+
l_target_table varchar2(128);
6+
l_owner_column varchar2(128);
57

68
function get_view(a_dba_view_name varchar2) return varchar2 is
79
l_invalid_object_name exception;
@@ -16,16 +18,18 @@ declare
1618
end;
1719

1820
begin
21+
l_target_table := get_view('dba_tab_privs');
22+
l_owner_column := case when l_target_table like 'dba%' then 'owner' else 'table_schema' end;
1923
execute immediate q'[
2024
select listagg(' - '||object_name,CHR(10)) within group(order by object_name)
2125
from (
2226
select column_value as object_name
2327
from table(:l_expected_grants)
2428
minus
2529
select table_name as object_name
26-
from ]'||get_view('dba_tab_privs')||q'[
30+
from ]'||l_target_table||q'[
2731
where grantee = SYS_CONTEXT('userenv','current_schema')
28-
and owner = 'SYS')]'
32+
and ]'||l_owner_column||q'[ = 'SYS')]'
2933
into l_missing_grants using c_expected_grants;
3034
if l_missing_grants is not null then
3135
raise_application_error(
@@ -37,4 +41,3 @@ begin
3741
end if;
3842
end;
3943
/
40-

0 commit comments

Comments
 (0)