Justin's answer is correct, but let me expand a bit.
Everyone who said that the table does not exist did not read your entire post. Since you can:
If I run the SP part from the query editor, it works fine
Obviously, there is a table. Obviously you have access to it. Otherwise, it will not work if it is clear.
but when I execute the whole SP, it throws an error.
This is because Oracle distinguishes between permissions granted directly and granted through the role.
Let's say I do this:
Create Table TABLE_A Create Role READ_ONLY Grant Select on TABLE_A to READ_ONLY Grant READ_ONLY to VIJAY
In the SQL Window / prompt, you can query this table without problems. So now you need to create a view
Create VIJAY.VIEW_A as SELECT * FROM TABLE_A
You will receive an error message that TABLE_A exists. Since the view is compiled, like a procedure, it runs without any role. Since it works without the READ_ONLY role, it does not ensure that TABLE_A exists. Now i need to do
Grant Select on TABLE_A to VIJAY.
Now that you have direct permission, you can compile the view or procedure / package that uses this table.
source share