Roles are never enabled during the execution of a procedure except in the special case of Invokers Rights which is a new feature in Oracle8i, release 8.1.
This fact is documented application developers guide:
To create a stand-alone procedure or function, or package specification or body, you must meet the following prerequisites:
You must have the CREATE PROCEDURE system privilege to create a procedure or package in your schema, or the CREATE ANY PROCEDURE system privilege to create a procedure or package in
another user's schema.
Attention: To create without errors, that is, to compile the procedure or package successfully, requires the following additional privileges: The owner of the procedure or package must have been explicitly granted the necessary object privileges for all objects referenced within the body of the code; the owner cannot have obtained required privileges through roles.
scott@10GR2> drop table t purge;
Table dropped.
scott@10GR2> create table t(x number);
Table created.
scott@10GR2> create role r1;
Role created.
scott@10GR2> grant select on t to r1;
Grant succeeded.
scott@10GR2> grant r1 to hr;
Grant succeeded.
scott@10GR2> connect hr/hr
Connected.
hr@10GR2> create synonym t for scott.t;
Synonym created.
hr@10GR2> create or replace procedure p1 as
2 l_val scott.t%rowtype;
3 begin
4 dbms_output.put_line (' procedure p1 invoked ');
5 end;
6 /
Warning: Procedure created with compilation errors.
hr@10GR2> show err;
Errors for PROCEDURE P1:
LINE/COL ERROR
-------- -----------------------------------------------------------------
2/8 PL/SQL: Item ignored
2/8 PLS-00201: identifier 'SCOTT.T' must be declared
hr@10GR2> create or replace procedure p2 as
2 l_val t%rowtype;
3 begin
4 dbms_output.put_line (' procedure p1 invoked ');
5 end;
6 /
Warning: Procedure created with compilation errors.
hr@10GR2> show err;
Errors for PROCEDURE P2:
LINE/COL ERROR
-------- -----------------------------------------------------------------
2/8 PL/SQL: Item ignored
2/8 PLS-00201: identifier 'T' must be declared
As stated from Product documentation, this can be solved by granting necessary privileges to owner rather that through Roles.
hr@10GR2> connect scott/tiger
Connected.
scott@10GR2> grant select on t to hr;
Grant succeeded.
scott@10GR2> connect hr/hr
Connected.
hr@10GR2> alter procedure p1 compile;
Procedure altered.
hr@10GR2> alter procedure p2 compile;
Procedure altered.
Thanks Mr Rajesh..
ReplyDeleteNice post...
http://babudba.blogspot.com
Thanks
THNX Rajesh...
ReplyDeleteThank you Rajesh!
ReplyDeleteGreat Rajesh
ReplyDeleteHave you ever thought about publishing an ebook or guest authoring
ReplyDeleteon other sites? I have a blog based on the same ideas you
discuss and would love to have you share some stories/information.
I know my readers would value your work. If you're even remotely interested, feel free
to shoot me an email.
Also visit my webpage :: Sheffield Plumbers ()
If you are facing this problem while trying to call a function or procedure in a package
ReplyDeletePlease have a look at the similar problem I faced and how to resolve it on my blogpot below
http://javaiscoool.blogspot.com/2014/04/pls-00201-identifier-must-be-declared.html
Really appreciated the information and please keep sharing, I would like to share some information regarding online training.Maxmunus Solutions is providing the best quality of this JBOSS Technology And this online training will be very convenient for the learner.And the training will be online and very convenient for the learner.
ReplyDeleteFor Joining online training batches please feel free to call or email us.
Email : minati@maxmunus.com
Contact No.-+91-9066638196/91-9738075708
website:-http://www.maxmunus.com/page/JBoss-Administration-Training