简体   繁体   English

在oracle 11g中创建用户的软件包

[英]a package to create a user in oracle 11g

create or Replace package body DBA_PACKAGE is
  procedure NewUser(username IN varchar2)
  is
  V_SQL varchar2(200); 
  V_ROLE varchar2(100);
  V_ROLE2 varchar2(100);
  begin

  V_SQL := 'Create user ' || username || ' identified by pass1234' ||' Password Expire'|| ' Default tablespace users' || ' Quota 1m on users';

  V_ROLE := 'Grant' || ' create session' || ' to ' || username;
  V_ROLE2 :='Grant' || ' connect' || ' to ' || username;


  dbms_output.put_line(V_SQL);
  dbms_output.put_line(V_ROLE);
  dbms_output.put_line(V_ROLE2);

  Execute immediate(V_SQL);
  execute immediate(V_ROLE);
  execute immediate(V_ROLE2);
  end NewUser;

set serveroutput on; 

exec DBA_PACKAGE.NewUser('Kevonia');

I got this error from SQL developer when executed 执行时我从SQL开发人员那里收到此错误

Error report -
ORA-01031: insufficient privileges
ORA-06512: at "SYSTEM.DBA_PACKAGE", line 20
ORA-06512: at line 1
01031. 00000 -  "insufficient privileges"
*Cause:    An attempt was made to change the current username or password
           without the appropriate privilege. This error also occurs if
           attempting to install a database without the necessary operating
           system privileges.
           When Trusted Oracle is configure in DBMS MAC, this error may occur
           if the user was granted the necessary privilege at a higher label
           than the current login.
*Action:   Ask the database administrator to perform the operation or grant
           the required privileges.
           For Trusted Oracle users getting this error although granted the
           the appropriate privilege at a higher label, ask the database
           administrator to regrant the privilege at the appropriate label.

First, don't create objects in schemas that Oracle provides. 首先,不要在Oracle提供的架构中创建对象。 SYS and SYSTEM should only have objects that Oracle installs as part of the database installation. SYSSYSTEM应该仅具有Oracle在数据库安装过程中安装的对象。 If you want to create your own objects, you'll want to create new schemas. 如果要创建自己的对象,则需要创建新的架构。

If you want to create a definer's rights stored procedure such as this, the owner of the procedure must have the necessary privileges granted directly to the user not via a role. 如果要创建这样的定义者权限存储过程,则该过程的所有者必须具有直接授予用户的必要特权,而不是通过角色。 The DBA role is a role like any other that has exactly the same restrictions-- if the owner of the procedure only has privileges to create a user via the DBA role, you'll get an ORA-01031 error. DBA角色是具有与其他角色完全相同的限制的角色-如果该过程的所有者仅具有通过DBA角色创建用户的特权,则会收到ORA-01031错误。 The owner of the package would need to be granted the CREATE USER privilege directly. 程序包的所有者需要直接被授予CREATE USER特权。

Alternately, you could declare the procedure as an invoker's rights stored procedure. 或者,您可以将该过程声明为调用者的权限存储过程。 That would allow you to use privileges granted via a role. 那将允许您使用通过角色授予的特权。 But that would mean that whoever called the procedure would need to have the ability to create a user (either via a role or via a direct grant). 但这意味着,调用该过程的人都需要具有创建用户的能力(通过角色或通过直接授予)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM