gpt4 book ai didi

oracle - 授予用户对 Oracle 架构的所有权限

转载 作者:行者123 更新时间:2023-12-04 14:12:19 26 4
gpt4 key购买 nike

有没有办法在 Oracle 模式上向用户授予所有权限?我尝试了以下命令,但它只授予对架构中特定表的权限。我想要的是授予此用户对给定架构的所有权限。

GRANT ALL ON MyTable TO MyUser;

最佳答案

您可以在循环中执行并通过动态 SQL 授予:

BEGIN
FOR objects IN
(
SELECT 'GRANT ALL ON "'||owner||'"."'||object_name||'" TO MyUser' grantSQL
FROM all_objects
WHERE owner = 'MY_SCHEMA'
AND object_type NOT IN
(
--Ungrantable objects. Your schema may have more.
'SYNONYM', 'INDEX', 'INDEX PARTITION', 'DATABASE LINK',
'LOB', 'TABLE PARTITION', 'TRIGGER'
)
ORDER BY object_type, object_name
) LOOP
BEGIN
EXECUTE IMMEDIATE objects.grantSQL;
EXCEPTION WHEN OTHERS THEN
--Ignore ORA-04063: view "X.Y" has errors.
--(You could potentially workaround this by creating an empty view,
-- granting access to it, and then recreat the original view.)
IF SQLCODE IN (-4063) THEN
NULL;
--Raise exception along with the statement that failed.
ELSE
raise_application_error(-20000, 'Problem with this statement: ' ||
objects.grantSQL || CHR(10) || SQLERRM);
END IF;
END;
END LOOP;
END;
/

关于oracle - 授予用户对 Oracle 架构的所有权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27353642/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com