授予在特定用户拥有的所有表上的select
我需要将特定用户拥有的所有表的select权限授予另一个用户。 我可以用一个命令来做到这一点:
Grant Select on OwningUser.* to ReceivingUser
或者我必须为每个表生成sql,其中包含以下内容:
Select 'GRANT SELECT ON OwningUser.'||Table_Name||'TO ReceivingUser' From All_Tables Where Owner='OWNINGUSER'
那么,这不是一个单一的声明,但它是关于你可以用oracle获得的:
BEGIN FOR R IN (SELECT owner, table_name FROM all_tables WHERE owner='TheOwner') LOOP EXECUTE IMMEDIATE 'grant select on '||R.owner||'.'||R.table_name||' to TheUser'; END LOOP; END;
表格+视图+错误报告
SET SERVEROUT ON DECLARE o_type VARCHAR2(60) := ''; o_name VARCHAR2(60) := ''; o_owner VARCHAR2(60) := ''; l_error_message VARCHAR2(500) := ''; BEGIN FOR R IN (SELECT owner, object_type, object_name FROM all_objects WHERE owner='SCHEMANAME' AND object_type IN ('TABLE','VIEW') ORDER BY 1,2,3) LOOP BEGIN o_type := r.object_type; o_owner := r.owner; o_name := r.object_name; DBMS_OUTPUT.PUT_LINE(o_type||' '||o_owner||'.'||o_name); EXECUTE IMMEDIATE 'grant select on '||o_owner||'.'||o_name||' to USERNAME'; EXCEPTION WHEN OTHERS THEN l_error_message := sqlerrm; DBMS_OUTPUT.PUT_LINE('Error with '||o_type||' '||o_owner||'.'||o_name||': '|| l_error_message); CONTINUE; END; END LOOP; END; /
从http://psoug.org/reference/roles.html ,为您的用户创build一个数据库上的过程来做到这一点:
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;
是的,可能的,运行这个命令:
可以说你有用户叫thoko
grant select any table, insert any table, delete any table, update any table to thoko;
注意:在oracle数据库上工作