?
Solved

Help with ORA-00942 when compiling package

Posted on 2007-12-07
2
Medium Priority
?
1,855 Views
Last Modified: 2008-02-01
Hi,
I am trying to compile a package in my custom schema. Where I am using v$sql and v$sql_bind_capture to capture all sqls with their bind values. I am getting PL/SQL: ORA-00942: table or view does not exist error. But from my custom schema I am able to execute the query and see the results. But it is giving the error when it thru a package. Can anyone help me. As these are SYS views do I need to create any synonym and views.

Regards

Sairam
CURSOR c_get_capture_sqls IS
		select distinct ash.client_id,du.name,
        	sql_bind_capture.value_string
        	from v$active_session_history ash,
        	dimuser du,
        	v$sql sql,
        	v$session sesion,
        	v$sql_bind_capture sql_bind_capture
         	where to_number(substr(ash.client_id,instr(ash.client_id,'/')+1))=du.dimuserid
         	AND ash.sample_time between sysdate - 60/2500 and sysdate
        	AND ash.sql_id = sql.sql_id (+)
        	And sql.HASH_VALUE = sql_bind_capture.HASH_VALUE
        	AND ash.SESSION_ID =sesion.SID (+)
        	AND ash.sql_id = sql_bind_capture.sql_id;

Open in new window

0
Comment
Question by:sairamb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 35

Expert Comment

by:johnsone
ID: 20427868
The problem is privileges.

Your account probably is granted the DBA role.  PL/SQL does not understand privileges granted through a role.  Never has, and probably never will.  You need to log in as SYS and grant the select privileges directly to your user.
0
 
LVL 9

Accepted Solution

by:
joebednarz earned 500 total points
ID: 20428542
I agree with the problem being a priv not granted.

One thing to remember with PL/SQL... if you create a procedure/package/function, by default, the privileges that are in place for the owning schema are the ones "given" to the user who is executing.  So, for instance:

SQL> connect scott

SQL> CREATE FUNCTION scott.show_emp
IS
tmp VARCHAR2(30);
BEGIN
  SELECT ename INTO tmp FROM emp WHERE empno=123;
  RETURN tmp;
END;
/

SQL> REVOKE select ON emp FROM joe;
SQL> GRANT execute ON show_emp TO joe;

SQL> connect joe
SQL> SELECT * FROM scott.EMP;  // returns an error

SQL> SELECT scott.show_emp FROM dual;  // returns employee #123's name

So, if you desire to have your PL/SQL procedure return data from a particular table, most likely, the schema owner (for the table) has not granted privs on the tables to the schema owner (for the procedure).  Finally, grant execute privilege for the procedure to whomever needs to get the data.

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question