Home » SQL & PL/SQL » SQL & PL/SQL » ORA-01031: insufficient privileges (Oracle Database 11g Release 11.2.0.1.0 - Production)
ORA-01031: insufficient privileges [message #627424] Tue, 11 November 2014 22:31 Go to next message
mokarem
Messages: 109
Registered: November 2013
Location: Dhaka
Senior Member

Hi,

Within a big package I have the below code:

 EXECUTE IMMEDIATE
            'create or replace view v_Check_custom as
            select distinct ''Cytotoxics     '' as "expression", Cytotoxics        from check_custom union all
            select distinct ''HormBC        ''  as "expression", HormBC            from check_custom union all
            select distinct ''LHRHas         '' as "expression", LHRHas            from check_custom union all
            select distinct ''C10A1Ezet      '' as "expression", C10A1Ezet         from check_custom union all
            select distinct ''Neurology      '' as "expression", Neurology         from check_custom union all
            select distinct ''EarlyAndAdv_BC '' as "expression", EarlyAndAdv_BC    from check_custom union all
            select distinct ''standardreporti'' as "expression", standardreporting from check_custom union all
            select distinct ''TArankings     '' as "expression", TArankings        from check_custom union all
            select distinct ''HormPCM        '' as "expression", HormPCM           from check_custom union all
            select distinct ''form_groups    '' as "expression", form_groups       from check_custom union all
            select distinct ''Exanta_ac_mkt  '' as "expression", Exanta_ac_mkt     from check_custom'
            ;


This code is generating below error:

ORA-01031: insufficient privileges
ORA-06512: at "SCOTT.AZ_DATA_MANAGEMENT", line 3659
ORA-06512: at "SCOTT.AZ_DATA_MANAGEMENT", line 3812
ORA-06512: at line 2
01031. 00000 - "insufficient privileges"

But I can execute the same statement in anonymous PL/SQL block in same user:
begin
  EXECUTE IMMEDIATE
            'create or replace view v_Check_custom as
            select distinct ''Cytotoxics     '' expression, Cytotoxics        from check_custom union all
            select distinct ''HormBC        '' expression, HormBC            from check_custom union all
            select distinct ''LHRHas         '' expression, LHRHas            from check_custom union all
            select distinct ''C10A1Ezet      '' expression, C10A1Ezet         from check_custom union all
            select distinct ''Neurology      '' expression, Neurology         from check_custom union all
            select distinct ''EarlyAndAdv_BC '' expression, EarlyAndAdv_BC    from check_custom union all
            select distinct ''standardreporti'' expression, standardreporting from check_custom union all
            select distinct ''TArankings     '' expression, TArankings       from check_custom union all
            select distinct ''HormPCM        '' expression, HormPCM         from check_custom union all
            select distinct ''form_groups    '' expression, form_groups         from check_custom union all
            select distinct ''Exanta_ac_mkt  '' expression, Exanta_ac_mkt     from check_custom'
            ;
end;     


In PL/SQL block it is not generating error.

Any idea to solve the issue please.
Re: ORA-01031: insufficient privileges [message #627425 is a reply to message #627424] Tue, 11 November 2014 22:48 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
privilege acquired via ROLE do NOT apply within a named PL/SQL procedure.

Direct GRANT is required to avoid this error.

>But I can execute the same statement in anonymous PL/SQL block in same user:
First do as below
SQL> SET ROLE NONE
Re: ORA-01031: insufficient privileges [message #627428 is a reply to message #627425] Tue, 11 November 2014 23:18 Go to previous messageGo to next message
mokarem
Messages: 109
Registered: November 2013
Location: Dhaka
Senior Member

Thanks, it works.

Re: ORA-01031: insufficient privileges [message #627430 is a reply to message #627428] Tue, 11 November 2014 23:20 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>Thanks, it works.
It would help those who follow if you actually posted details on what actually "worked".
Re: ORA-01031: insufficient privileges [message #627431 is a reply to message #627430] Tue, 11 November 2014 23:51 Go to previous messageGo to next message
mokarem
Messages: 109
Registered: November 2013
Location: Dhaka
Senior Member

Initially I granted DBA to abc and I found the above issue.

To solve this I have granted privileges as below:

grant create any view to abc;


It resolved the issue.
Re: ORA-01031: insufficient privileges [message #627433 is a reply to message #627431] Wed, 12 November 2014 00:13 Go to previous messageGo to next message
Michel Cadot
Messages: 68647
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Why ANY? Grant just CREATE VIEW.

Re: ORA-01031: insufficient privileges [message #627435 is a reply to message #627433] Wed, 12 November 2014 00:17 Go to previous message
mokarem
Messages: 109
Registered: November 2013
Location: Dhaka
Senior Member

Thanks again.

I hope this also will work.

Previous Topic: Conditional INSERT
Next Topic: Exporting multiline feeds to a single line in Oracle 8i
Goto Forum:
  


Current Time: Fri Apr 26 17:13:18 CDT 2024