GRANT 权限给动态用户 SQL
GRANT Permission to dynamic user SQL
我授权的用户名是可以更改的。因此,我想写一个 SQL,如下所示;
grant ANALYZE ANY DICTIONARY to (select USERNAME from DBA_USERS where DEFAULT_TABLESPACE = 'MCP_DATA');
但是,它给出了一个错误。
所有意见和建议将不胜感激。
使用EXECUTE IMMEDIATE
:
DECLARE
username DBA_USERS.USERNAME%TYPE;
BEGIN
SELECT USERNAME
INTO username
FROM DBA_USERS
WHERE DEFAULT_TABLESPACE = 'MCP_DATA';
EXECUTE IMMEDIATE 'GRANT ANALYZE ANY DICTIONARY TO ' || username;
END;
/
我授权的用户名是可以更改的。因此,我想写一个 SQL,如下所示;
grant ANALYZE ANY DICTIONARY to (select USERNAME from DBA_USERS where DEFAULT_TABLESPACE = 'MCP_DATA');
但是,它给出了一个错误。 所有意见和建议将不胜感激。
使用EXECUTE IMMEDIATE
:
DECLARE
username DBA_USERS.USERNAME%TYPE;
BEGIN
SELECT USERNAME
INTO username
FROM DBA_USERS
WHERE DEFAULT_TABLESPACE = 'MCP_DATA';
EXECUTE IMMEDIATE 'GRANT ANALYZE ANY DICTIONARY TO ' || username;
END;
/