Home » SQL & PL/SQL » SQL & PL/SQL » cannt access v$ views in PL/Sql
cannt access v$ views in PL/Sql [message #9540] Tue, 18 November 2003 21:41 Go to next message
Puneet Vats
Messages: 33
Registered: June 2002
Member
hi dears,
i can select from v$session from sql direct but when i put it any named pl/sql block then it gives me an error.
table or view does not exist please tell me
what should i do.
love
puneet vats
Re: cannt access v$ views in PL/Sql [message #9545 is a reply to message #9540] Tue, 18 November 2003 23:40 Go to previous message
Maaher
Messages: 7065
Registered: December 2001
Senior Member
Your user most probably has received the grant via a role (Select on V$SESSION is part of the SELECT_CATALOG_ROLE which, in turn, is part of the DBA, IMP/EXP_FULL_DATABASE roles). The problem with grants through roles is that they are NOT valid in a NAMED PL/SQL block. There's a very good reason for this:
----------------------------------------------------------------------
<I>Problem Description:
~~~~~~~~~~~~~~~~~~~~
All roles are disabled in any *named* PL/SQL block that
     * is created in a user schema that does not own the object being
        referenced in the PL/SQL block
     * can be executed as a user other than the owner of the PL/SQL block
This applies to stored procedures and functions, as well as database triggers.

You can also see this by selecting from the data 
dictionary view called SESSION_ROLES.

This view shows all roles that are currently enabled.  If you query SESSION_ROLES from a stored object, 
the query will not return any rows.
This is not true in Oracle8i when the stored object is created with 
AUTHID  CURRENT_USER.

Roles vs. GRANTs and REVOKEs:
-----------------------------
Do not confuse roles with GRANTs and REVOKEs 
-- Roles are meant to be toggled on and off on a per session basis, 
whereas GRANTs and REVOKEs (as well as any associated dependencies) 
updates the data dictionary because they are DDL   operations.
This is why it becomes an issue of gross ambiguity:  A user can potentially 
log on in the form of two sessions, one with the role enabled, the 
other one with the role disabled, and the outcome of both sessions will not be the same.

Hence, the restriction that stored object creation cannot depend on privileges 
granted through a role is added in the Oracle7 to avoid ambiguous cases of this nature. 
Notice that anonymous PL/SQL blocks are not bound to this restriction, 
therefore they are executed based on privileges granted through enabled roles. </I>

----------------------------------------------------------------------

So, the solution to your problem is to perform the GRANT directly to the user...

MHE
Previous Topic: hourly count
Next Topic: ORA-06502 when executing procedure or function
Goto Forum:
  


Current Time: Thu Apr 25 19:23:16 CDT 2024