AI智能
改变未来

oracle批量授权

[code]背景:oracle数据库,存在用户A和用户B对单表授权:grant insert,select,update,delete on A.TABLE1 to B;批量授权:1、先查出所有授权语句A用户登录然后执行以下sql;select \'grant insert,select,update,delete on A.\' || table_name || \' to B;\' from user_tables或者执行以下sqlselect \'grant insert,select,update,delete on A.\' || table_name || \' to B;\' from all_tables where owner = ‘A’2、执行上一步得到的结果grant insert,select,update,delete on A.TABLE1 to B;grant insert,select,update,delete on A.TABLE2 to B;......利用存储过程批量授权:create or replace procedure test(A in varchar2, B in varchar2) isv_sql varchar2(1000);cursor v_cur isselect t.* from dba_tables t where t.OWNER = A;beginfor v_row in v_cur loopv_sql := \'grant select on \' || A || \'.\' || v_row.table_name ||\' to \' || B;execute immediate v_sql;end loop;end test;

 

赞(0) 打赏
未经允许不得转载:爱站程序员基地 » oracle批量授权