Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ORA-00942: table or view does not exist (works when a separate sql, but does not work inside a oracle function)

When I have a sql statement like select * from table1, it works great, but as soon as I put it into a function, I get:

ORA-00942: table or view does not exist  

How to solve this?

like image 210
Victor Avatar asked Jul 12 '11 19:07

Victor


People also ask

How do I fix Oracle error ORA 00942 table or view does not exist?

Reference the Correct Schema You may be seeing the Ora-00942 error because you are referencing a table or view in a schema which you did not create but one that is in another schema. To correctly execute the query from another schema, you must reference the table by the schema name.

How resolve table or view does not exist in SQL Developer?

check the spelling of the table or view name. check that an existing table or view name exists. contact the DBA if the table needs to be created or if user or application privileges are required to access the table.

What is the meaning of table or view does not exist in SQL?

It means exactly what it says, the table or view you are executing your query on does not exist in your schema. To explain, whenever you execute a query which includes a table, view, synonym or a cluster which does not exist into the schema with which you are connected the SQL engine will show you this error.

How do you grant select to all tables in a schema?

Grant SELECT on all tables in a schema to a user Unfortunately, Oracle doesn't directly support this using a single SQL statement. To work around this, you can select all table names of a user (or a schema) and grant the SELECT object privilege on each table to a grantee.


1 Answers

There's a strong chance that the privileges to select from table1 have been granted to a role, and the role has been granted to you. Privileges granted to a role are not available to PL/SQL written by a user, even if the user has been granted the role.

You see this a lot for users that have been granted the dba role on objects owned by sys. A user with dba role will be able to, say, SELECT * from V$SESSION, but will not be able to write a function that includes SELECT * FROM V$SESSION.

The fix is to grant explicit permissions on the object in question to the user directly, for example, in the case above, the SYS user has to GRANT SELECT ON V_$SESSION TO MyUser;

like image 104
Steve Broberg Avatar answered Sep 18 '22 15:09

Steve Broberg