Dtabpriv (dtabpriv.sql)
What This Script Does
Section titled “What This Script Does”This script provides a comprehensive view of table privileges across the database, showing who has access to which tables and what operations they can perform. Essential for security audits and access control management.
The Script
Section titled “The Script”rem dtabpriv.sqlremttitle 'TABLE PRIVILEGES'remset linesize 250remcol grantee format a20 heading 'GRANTEE'col owner format a8 heading 'OWNER'col table_name format a30 heading 'TABLE NAME'col grantor format a8 heading 'GRANTOR'col privilege format a9 heading 'PRIVILEGE'col grantable format a9 heading 'GRANTABLE'remselect grantee, owner, table_name, grantor, privilege, grantable from sys.dba_tab_privs where grantee like nvl(upper('&grantee'),'%') and owner like nvl(upper('&owner'),'%') and table_name like nvl(upper('&table'),'%') and grantor like nvl(upper('&grantor'),'%')/
Parameters
Section titled “Parameters”The script prompts for:
- &User - or role receiving the privilege (use % for all)
- &Table - owner to filter (use % for all)
- &Table - name pattern to filter (use % for all)
- &User - who granted the privilege (use % for all)
-- Basic usage@dtabpriv.sql
-- When prompted, enter:-- grantee: User or role receiving the privilege (use % for all)-- owner: Table owner to filter (use % for all)-- table: Table name pattern to filter (use % for all)-- grantor: User who granted the privilege (use % for all)
Sample Output
Section titled “Sample Output”TABLE PRIVILEGES
GRANTEE OWNER TABLE NAME GRANTOR PRIVILEGE GRANTABLE-------------------- -------- ------------------------------ -------- --------- ---------APP_USER HR EMPLOYEES HR SELECT NOAPP_USER HR EMPLOYEES HR INSERT NOAPP_USER HR EMPLOYEES HR UPDATE NOAPP_USER HR DEPARTMENTS HR SELECT YESPUBLIC HR COUNTRIES HR SELECT NOREPORT_ROLE HR EMPLOYEES SYS SELECT NOREPORT_ROLE HR DEPARTMENTS SYS SELECT NOHR_ADMIN HR EMPLOYEES HR ALTER NOHR_ADMIN HR EMPLOYEES HR DELETE NOHR_ADMIN HR EMPLOYEES HR INDEX NOHR_ADMIN HR EMPLOYEES HR INSERT NOHR_ADMIN HR EMPLOYEES HR SELECT YESHR_ADMIN HR EMPLOYEES HR UPDATE NO