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 7493281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:51:48+00:00 2026-05-29T16:51:48+00:00

I want to do something that’s conceptually simple but seems to be a lot

  • 0

I want to do something that’s conceptually simple but seems to be a lot more complex in reality.

Basically, whenever a new table is created for a couple of users in our database, I want to grant select permissions to a role. Basically this:

grant select on TABLENAME to READROLE;

So far my trigger looks something like this:

CREATE OR REPLACE TRIGGER osmm_grant_on_creation

AFTER CREATE ON OSMM.SCHEMA

BEGIN

    //grant goes here

END

Problem is, I can’t figure out how to join the two together by getting the name of the newly created table and referencing it through the trigger to the grant.
Any suggestions? Thanks.

  • 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-29T16:51:52+00:00Added an answer on May 29, 2026 at 4:51 pm

    It’s likely more complex than you’re even thinking. The GRANT statement is DDL which means that it issues implicit commits which means that you cannot put it in a trigger directly. Your trigger would need to submit a job which ran in a separate session after the triggering transaction committed which would actually do the grant. And that means that you have to use the older DBMS_JOB package to schedule the job since the more modern DBMS_SCHEDULER also implicitly commits.

    Since you shouldn’t be creating tables on the fly in Oracle in the first place, the proper place for this sort of grant is in the build scripts that you run to create the table in the first place. Relying on triggers to do things like grants just tends to make it more difficult to do builds properly because running exactly the same script in two different environments may generate two different results because of differences in the trigger.

    If you’re determined to go down this path, however, you’d probably want something like

    A procedure that grants the privilege

    CREATE OR REPLACE PROCEDURE grant_select_to_readrole( p_table_name IN VARCHAR2 )
    AS
    BEGIN
      EXECUTE IMMEDIATE 'grant select on ' || p_table_name || ' to readrole';
    END;
    

    And a trigger that submits a job that calls this procedure

    CREATE OR REPLACE TRIGGER osmm_grant_on_creation
      AFTER CREATE ON OSMM.SCHEMA
    AS
      l_jobno PLS_INTEGER;
    BEGIN
      dbms_job.submit( l_jobno,
                       'BEGIN grant_select_to_readrole( ''' || ora_dict_obj_name || ''' ); END;',
                       sysdate + interval '10' second );
    END;
    

    If you were to try to issue DDL in the schema-level trigger itself, you’d get an error

    SQL> ed
    Wrote file afiedt.buf
    
      1  create or replace trigger after_create_on_scott
      2    after create on schema
      3  declare
      4  begin
      5    execute immediate 'grant select on scott.emp to hr';
      6* end;
    SQL> /
    
    Trigger created.
    
    SQL> create table foo( col1 number );
    create table foo( col1 number )
    *
    ERROR at line 1:
    ORA-00604: error occurred at recursive SQL level 1
    ORA-30511: invalid DDL operation in system triggers
    ORA-06512: at line 3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know it's simple to implement, but I want to reuse something that already
I want to write something that acts just like confirm() in javascript, but I
I want to make something that makes much sense, but I think its not
this is something that i don't want to program, but i was looking for
Well, Maven is too good, when talking about speed. But I want something that
I want something that looks like this http://jsfiddle.net/mazlix/VBzau/3/ But I don't want to have
We already have a good build server in Hudson but we want something that
I want to start playing with non-relational database, but want something that is popularly
I am retrieving all tables, and make sql. But I want something that can
I want something that's simple, in-depth and explains from basics.

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.