Grant Select on all Tables Owned By Specific User

后端 未结 4 1157
春和景丽
春和景丽 2020-12-02 16:55

I need to grant select permission for all tables owned by a specific user to another user. Can I do this with a single command along the lines of:

Grant Sel         


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-02 17:35

    From http://psoug.org/reference/roles.html, create a procedure on your database for your user to do it:

    CREATE OR REPLACE PROCEDURE GRANT_SELECT(to_user in varchar2) AS
    
      CURSOR ut_cur IS SELECT table_name FROM user_tables;
    
      RetVal  NUMBER;
      sCursor INT;
      sqlstr  VARCHAR2(250);
    
    BEGIN
        FOR ut_rec IN ut_cur
        LOOP
          sqlstr := 'GRANT SELECT ON '|| ut_rec.table_name || ' TO ' || to_user;
          sCursor := dbms_sql.open_cursor;
          dbms_sql.parse(sCursor,sqlstr, dbms_sql.native);
          RetVal := dbms_sql.execute(sCursor);
          dbms_sql.close_cursor(sCursor);
    
        END LOOP;
    END grant_select;
    

提交回复
热议问题