将 Oracle 中的 DDL 授予特定用户

发布于 2024-09-18 03:23:42 字数 156 浏览 5 评论 0原文

如何在oracle中授予DDL权限?

在数据库上,我有用户 SCHEMA_1、SCHEMA_2 和 SCHEMA_3

,现在我希望从 schema_1 只能在 SCHEMA_2 上执行 DDL

是否可以从 SCHEMA_2 级别或仅从系统授予授权?

How to grant DDL privileges in oracle ?

On database I've users SCHEMA_1, SCHEMA_2 and SCHEMA_3

and now i want to from schema_1 be able to do DDL only on SCHEMA_2

Is the grant is possible from SCHEMA_2 level or system only ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

滿滿的愛 2024-09-25 03:23:42

Oracle 不是这样工作的。您必须向该用户授予CREATE ANY [OBJECT_TYPE]权限,并拥有一个系统事件触发器来限制他们在您不希望他们使用的架构中工作。

警告:使用了 DBMS_STANDARD 的未记录/记录不足的功能。

CREATE OR REPLACE TRIGGER schema_1_on_schema_2
  before DDL on DATABASE
as
  has_dba_priv number;
  n            number;
  stmt         ora_name_list_t;
BEGIN
  -- exit if user is object owner
  if ora_dict_obj_owner = ora_login_user then
    return
  end if;

  -- exit if user has dba directly
  select count(*)
    into has_dba_priv
    from dba_role_privs 
   where granted_role = 'DBA'
     and grantee = ora_login_user;

  if has_dba_priv <> 0 then
    return;
  end if;

  -- exit if action is an automatic recompile
  stmt := null;
  n := ora_sql_txt(sql_text);
  FOR i IN 1..n LOOP
    stmt := stmt || sql_text(i);
  END LOOP;

  if stmt like 'ALTER % COMPILE REUSE SETTINGS%' then
    return;
  end if;

  -- you should probably organize this into a database table of permitted
  -- schema_x can affect schema_y, but this is a "basic" example
  if     (ora_dict_obj_owner = 'SCHEMA_2')
     and (ora_login_user = 'SCHEMA_1') then 
    null;
  else
    raise_application_error (-20000, 'User ' || ora_login_user || 
         ' is not permitted to execute DDL against ' || ora_dict_obj_owner);
  end if;
end;

Oracle doesn't work that way. You'd have to grant CREATE ANY [OBJECT_TYPE] to that user and have a system event trigger which restricts them from working in the schemas you don't want them to.

Warning: Undocumented / underdocumented features of DBMS_STANDARD are used.

CREATE OR REPLACE TRIGGER schema_1_on_schema_2
  before DDL on DATABASE
as
  has_dba_priv number;
  n            number;
  stmt         ora_name_list_t;
BEGIN
  -- exit if user is object owner
  if ora_dict_obj_owner = ora_login_user then
    return
  end if;

  -- exit if user has dba directly
  select count(*)
    into has_dba_priv
    from dba_role_privs 
   where granted_role = 'DBA'
     and grantee = ora_login_user;

  if has_dba_priv <> 0 then
    return;
  end if;

  -- exit if action is an automatic recompile
  stmt := null;
  n := ora_sql_txt(sql_text);
  FOR i IN 1..n LOOP
    stmt := stmt || sql_text(i);
  END LOOP;

  if stmt like 'ALTER % COMPILE REUSE SETTINGS%' then
    return;
  end if;

  -- you should probably organize this into a database table of permitted
  -- schema_x can affect schema_y, but this is a "basic" example
  if     (ora_dict_obj_owner = 'SCHEMA_2')
     and (ora_login_user = 'SCHEMA_1') then 
    null;
  else
    raise_application_error (-20000, 'User ' || ora_login_user || 
         ' is not permitted to execute DDL against ' || ora_dict_obj_owner);
  end if;
end;
何止钟意 2024-09-25 03:23:42

更好的方法可能是将 schema_2 DDL 嵌入到过程中,并将这些过程的执行权限授予 schema_1。对您的要求进行更全面的解释可能会带来更全面/更好的答案。

A better way might be to embed the schema_2 DDL into procedures and grant execute on those procedures to schema_1. A fuller explanation of your requirements may lead to fuller / better answers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文