遭遇错误:ORA-01031

 
遭遇错误:ORA-01031 insufficient privileges

原因:
 
用户拥有的role权限在存储过程和函数是不可用的,加入Authid Current_User时存储过程和函数可以使      用role权限,否则需要显式进行系统权限,如grant create table to suk;但这种方法太麻烦。
 
解决方法:
 
可以通过的在创建函数、存储过程时的名称后加上”authid current_user“就可以了。

例子:
 
加:AUTHID   CURRENT_USER,否则执行时报:ORA-01031 insufficient privileges
 
存储过程:

 create or replace procedure p_createTempSeq (sequenceName in varchar2)
 AUTHID   CURRENT_USER
   is
   strsql varchar2(1000);
   begin
   strsql := 'create sequence seq_'||sequenceName||' minvalue 10 maxvalue 99 start with 10 increment by 1 nocache';
   execute immediate strsql;
   commit;  
   end p_createTempSeq;
 
函数:
 
CREATE OR REPLACE FUNCTION f_getSeq 
RETURN varchar2
authid current_user IS
  tempID varchar2(2);
  testID varchar2(10); 
  strsql varchar2(2000);
BEGIN   
  --建序列器,调上面的存储过程,  这里要注意序列已经存在就先drop
   strsql :='call p_createTempSeq( ''testDefaultValue_test'')'; 
   execute immediate strsql;   
   select  seq_testDefaultValue_test.Nextval into tempID    from dual;
   testID := TO_CHAR(SYSDATE, 'YYYYMMDD') ||tempID;
   RETURN (testID);
END;
 
函数调用方法:
 
 set serveroutput on
  declare
     testID varchar2(10);
  begin
    testID:=  f_getSeq;
    dbms_output.put_line (testID);
  end;
 

参考: [url]http://www.orafaq.com/forum/t/139582/0/[/url] , [url]http://topic.csdn.net/t/20060429/21/4724465.html[/url]

你可能感兴趣的:(职场,休闲,ORA-01031,authid,current_user)