Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 568227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:09:59+00:00 2026-05-13T13:09:59+00:00

Similar to this question , I would like to know how to generate all

  • 0

Similar to this question, I would like to know how to generate all GRANT statements issued to all roles in a set of schemas and a list of roles whose names end in “PROXY”. I want to recreate statements like:

GRANT SELECT ON TABLE_NAME TO ROLE_NAME;
GRANT EXECUTE ON PACKAGE_NAME TO ROLE_NAME;

The purpose is to help migrate from a development database to a testing database (Oracle 11g). There are some tools that attempt to do this automatically, but often fail.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T13:10:00+00:00Added an answer on May 13, 2026 at 1:10 pm

    This script generates a list of all table privileges granted to roles…

    select 'grant '||privilege||' on '||owner||'.'||table_name||' to '||grantee
             ||case when grantable = 'YES' then ' with grant option' else null end
             ||';'
    from dba_tab_privs
    where owner in ('A', 'B')
    and grantee in ( select role from dba_roles )
    order by grantee, owner
    /
    

    Note that I don’t restrict the grantee roles, because your question is vague on that point. You may need to add a filter to the sub_query ondba_roles. If you have roles granted to other roles you will want to pick those up too …

    select 'grant '||granted_role||' to '||grantee
             ||case when admin_option = 'YES' then ' with admin option' else null end
             ||';'
    from dba_role_privs
    where grantee in ( select role from dba_roles )
    order by grantee, granted_role
    /
    

    To get your list of roles …

    select 'create role '||role ||';'
    from dba_roles
    where role like '%PROXY'
    /
    

    Note that these scripts don’t generate grants for system privileges. Also, life is slightly more complicated if you use directory objects because that requires an additional key word…

    select 'grant '||privilege||' on '||owner||'.'||table_name||' to '||grantee
             ||case when grantable = 'YES' then ' with grant option' else null end
             ||';'
    from dba_tab_privs
    where owner in ('A', 'B')
    and grantee in ( select role from dba_roles )
    and table_name not in ( select directory_name from dba_directories )
    union all
    select 'grant '||privilege||' on directory '||table_name||' to '||grantee
             ||case when grantable = 'YES' then ' with grant option' else null end
             ||';'
    from dba_tab_privs
    where grantee in ( select role from dba_roles )
    and table_name  in ( select directory_name from dba_directories )
    /
    

    edit

    In 9i Oracle introduced the DBMS_METADATA package which wraps up a lot of these sorts of queries in a simple PL/SQL API. For instance, this call will prorduces a CLOB with all the object privileges granted to A …

    select dbms_metadata.get_granted_ddl('OBJECT_GRANT', 'A') from dual
    /
    

    This is obviously a lot simpler than rolling our own.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a similar question to this one . I would like to convert
My question is similar to this one , but I would like to replicate
Seen many other similar questions like this on this website and i would say
I would imagine this might use Reflection.Emit, but a similar question on SO only
This is similar to a recent question. I will be maintaining sorted a list
Similar to this question I am using a custom VirtualPathProvider to retrieve views that
Similar to this question asking about relatively light-weight data entry / editor application development,
Similar to this question only the other way of flow. Insert Picture into SQL
Similar to this question: link However I have already mastered that. My problem is
Similar to this question , except the console program being wrapped up in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.