The user has access to V$DATABASE via a role. You need to grant privileges on this object (V$DATABASE is a synonym for SYS.V_$DATABASE) directly to the user, then your code will compile. This is due to the fact that Roles are not enabled in DEFINER RIGHTS procedures.
GRANT SELECT ON sys.v$_database TO user;
Main Topics
Browse All Topics





by: mrjoltcolaPosted on 2009-09-21 at 16:09:54ID: 25388511
v$database is a synonym and its base view is sys.v_$database
Since SYSTEM has access to that view via the DBA role, in order to use it in a procedure, you'll need to grant explicit object privileges on that object to system as the ROLE will not be in effect.
connect / as sysdba
grant select on v_$database to system;
-- Then create procedure as SYSTEM
CREATE OR REPLACE FUNCTION getdbname RETURN VARCHAR2
AS
v_DBname varchar2(100);
BEGIN
select name into v_DBname from sys.v_$database;
return v_DBname;
END;
/