Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Error execute procedure "ORA-01031: insufficient privileges"

825167Dec 19 2010 — edited Dec 19 2010
Hi everybody,

I've built a procedure to audit:

create or replace procedure audit_login(user in varchar2, flag in number)
as
begin

if flag = 1 then
execute immediate 'AUDIT CONNECT BY ' || user ||' WHENEVER SUCCESSFUL';
elsif flag = 2 then
execute immediate 'AUDIT CONNECT BY ' || user ||' WHENEVER NOT SUCCESSFUL';
elsif flag = 3 then
execute immediate 'AUDIT CONNECT BY ' || user;
end if;

end;

But, when i execute it:

begin
audit_login('scott', 1);
end;

I get an error:

begin
*

ERROR at line 1:
ORA-01031: insufficient privileges
ORA-06512: at "SYSTEM.AUDIT_LOGIN", line 6
ORA-06512: at line 3

In addition, I've login by SYSTEM account. The command: audit connect by scott whenever successful; => Executed successfully! I tried to replace the first execute in the procedure:

create or replace procedure audit_login(user in varchar2, flag in number)
as
begin

if flag = 1 then
execute immediate 'audit connect by scott whenever successful';
elsif flag = 2 then
execute immediate 'AUDIT CONNECT BY ' || user ||' WHENEVER NOT SUCCESSFUL';
elsif flag = 3 then
execute immediate 'AUDIT CONNECT BY ' || user;
end if;

end;

But still error!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 16 2011
Added on Dec 19 2010
4 comments
5,387 views