包怎么运作?

时间:2016-03-26 23:23:35

标签: oracle11g package

我创建了一个包含两个过程的包,其中一个是创建用户。但是,当我执行该过程虽然成功,但我没有看到用户创建..

    create or replace PACKAGE APPLICATIONPACKAGE AS 
    procedure CreateSingleUser( userName in VARCHAR2, rolename in VARCHAR2);
    PROCEDURE DeleteUser(userName in varchar2);
    END APPLICATIONPACKAGE;
    /
    create or replace PACKAGE BODY                                                                             
    APPLICATIONPACKAGE AS

     procedure CreateSingleUser( userName in VARCHAR2, rolename in VARCHAR2)
     AS
    dynamicsql  VARCHAR2 (2000);
    BEGIN

    BEGIN
     if rolename='APPADMIN' OR rolename='APPMODIFIER' or rolename='APPVIEWER'  
     THEN --limit user input to specific roles
 ----assign dynamic sql to a variable for excecution by excecute immediate
     dynamicsql :='CREATE USER ' || userName|| ' IDENTIFIED BY pass1234 DEFAULT  
      TABLESPACE USERS QUOTA 1M ON USERS PASSWORD EXPIRE';
      DBMS_OUTPUT.PUT_LINE (dynamicsql);
     EXECUTE IMMEDIATE dynamicsql;
     EXECUTE IMMEDIATE 'GRANT ' || rolename || ' TO ' || userName || '';
     EXECUTE IMMEDIATE 'GRANT CREATE SESSION TO ' || userName; 
     else
     DBMS_OUTPUT.PUT_LINE('Not a valid role...sorry role specified not given to    
      a user');
     END IF;
     END;
     END CreateSingleUser;
     PROCEDURE DeleteUser(userName in varchar2)
      AS
   deleteSql  VARCHAR2 (500);

   BEGIN
    deleteSql :='DROP USER ' || userName; -- assign drop user command to    
    variable delete sql
    DBMS_OUTPUT.PUT_LINE (deleteSql);
    EXECUTE IMMEDIATE deleteSql;  -- excecute the sql dynamically;
    END DeleteUser;
    ----- end procedure delete user-------

    END APPLICATIONPACKAGE;

0 个答案:

没有答案