我需要创建一个执行以下操作的过程:
它必须遍历表并为用户删除所有表。到目前为止,我有#1和#3工作。但我需要添加#2,我似乎无法弄清楚如何去做。这是我的#2代码,我一直收到错误:
//REVOKING OBJECT PRIVILEGES
CREATE or REPLACE PROCEDURE deactivate_user
(p_username IN VARCHAR2) AS
l_username VARCHAR2(30) := UPPER(p_username);
BEGIN
FOR rec IN (SELECT * FROM dba_tab_privs WHERE GRANTEE = p_username)
LOOP
EXECUTE IMMEDIATE 'REVOKE ALL PRIVILEGES ON TABLE '||rec.owner||'.'||rec.table_name||' FROM '||rec.grantee;
END LOOP;
END;
/
//REVOKING OBJECT PRIVILEGES
CREATE or REPLACE PROCEDURE deactivate_user
(p_username IN VARCHAR2) AS
l_username VARCHAR2(30) := UPPER(p_username);
BEGIN
FOR rec IN (SELECT * FROM dba_tab_privs WHERE GRANTEE = p_username)
LOOP
EXECUTE IMMEDIATE 'REVOKE ALL PRIVILEGES ON TABLE '||rec.owner||'.'||rec.table_name||' FROM '||rec.grantee;
END LOOP;
END;
/
当我尝试执行代码时:SQL> exec deactivate_user('BLAKE'),我收到此错误: 错误:第1行: ORA-06550:表或视图不存在 ORA-06512:在“SYS.DEACTIVATE_USER”第7行
非常感谢您的帮助!
答案 0 :(得分:0)
表权限的正确命令是:
REVOKE ALL PRIVILEGES FROM ...
或:
REVOKE READ FROM ...
同样添加TABLE关键字也更好。
所以EXECUTE IMMEDIATE语句应该是:
EXECUTE IMMEDIATE 'REVOKE ALL PRIVILEGES ON TABLE ' || rec.owner || '.' || rec.table_name ||' FROM '|| rec.grantee;
或:
EXECUTE IMMEDIATE 'REVOKE ' || rec.privilege || ' ON TABLE ' || rec.owner || '.' || rec.table_name ||' FROM '|| rec.grantee;
<强>更新强>
我的第一个答案中遗漏了最重要的东西:桌主。