We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Oracle  :  Can't access sys.v_$instance in  a PL/SQL programm unit

hiranya
hiranya asked
on
Medium Priority
1,224 Views
Last Modified: 2008-01-09
Hi.

I tried to execute following SQL statement in a PL/SQL programm unit. But it raise an error when I try to compile the programme unit.

SQL> SELECT instr(lower(instance_name),'tst')
  2  FROM sys.v_$instance;

INSTR(LOWER(INSTANCE_NAME),'TST')
---------------------------------
                                3

SQL> CREATE OR REPLACE procedure test as
  2  ext number;
  3  begin
  4  SELECT instr(lower(instance_name),'tst')
  5  into ext
  6  FROM sys.v_$instance;
  7  dbms_output.put_line(ext);
  8  end;
  9  /

Warning: Procedure created with compilation errors.

SQL> show errors
Errors for PROCEDURE TEST:

LINE/COL ERROR
-------- -----------------------------------------------------------------
4/1      PL/SQL: SQL Statement ignored
6/10     PL/SQL: ORA-00942: table or view does not exist
SQL>

Please help.

Regards
Hiranya
Comment
Watch Question

Commented:
If you have access to this from sql*plus by describing it, but it doesn't work in a procedure, it is because your grant to the table is via a role. There are two ways around this. Have the dba do a DIRECT GRANT to your user, not through a role.

The reason is that pl/sql procedures are, by default, run with definer rights. Definer rights procedures suspend all roles while executing. If you turn this into an invoker rights procedure, then the procedure will execute with roles enabled, but whoever tries to run the procedure will also need rights to sys.v_$instance to run the procedure. This is the trade-off. Definer rights, you can grant execute on the procedure and anyone can do what the procedure enables, but the grants have to be direct, not roles.

Invoker rights, the roles stay active, but only those who have the grants to the objects in the procedure can access them.

To turn your procedure into an invoker rights procedure do this:

CREATE OR REPLACE procedure test AUTHID CURRENT_USER As
ext number;
begin
SELECT instr(lower(instance_name),'tst')
into ext
FROM sys.v_$instance;
dbms_output.put_line(ext);
end;
/

See here for additional information
http://www.experts-exchange.com/Databases/Oracle/Q_21762459.html

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
RCorfman......

Thank you very much for your answer.
I granted the select on priveleges to v_$instance. Now its working. Thanks a lot.

Regards
Hiranya.

Commented:
invoker rights vs. definer rights is one of the items in Oracle that is not well understood... in fact, most people have never even heard of it. Glad I could help.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.