Reputation: 103
I'm having problems while executing a stored procedure in Oracle.
Below is the stored procedure:
CREATE OR REPLACE Procedure xxxlist
(yyyid in NUMBER)
IS
xid number(6);
cursor c1 is select distinct xxxID from MXS.Y where YID=yyyid;
BEGIN
IF NOT c1%ISOPEN THEN
OPEN c1;
END IF;
LOOP
FETCH c1 into xid;
dbms_output.put_line(TO_CHAR(xid));
EXIT WHEN c1%NOTFOUND;
END LOOP;
CLOSE c1;
END;
When I create the stored procedure, I get the following error:
Warning: Procedure created with compilation errors.
I execute the below command to provide me more details on the above abstract error message.
SHO ERR;
I get the below details in response to the above command:
Errors for PROCEDURE XXXLIST:
LINE/COL ERROR
-------- -----------------------------------------------------------------
5/18 PL/SQL: SQL Statement ignored
5/52 PL/SQL: ORA-00942: table or view does not exist
Now, I understand that there is a problem with the table name or sql query itself. So, I try to execute the SQL query alone, seperately, outside the PRODECURE, to see what is wring with the table or query.
select distinct xxxID from MXS.Y where YID=yyyid;
But, I do not find any issues with the above query. The query runs fine and I get proper result.
So, I do not know why the procedure is having problems while executing. Can anyone help?
Upvotes: 2
Views: 1194
Reputation: 48111
A possible explanation is that the account you are running in has been granted access to the table through a role. In Oracle, access granted through roles affects standalone SQL statements but not SQL statements embedded in PL/SQL.
If this is the case, the owner of the table (or a DBA) would have to grant select access on the table directly to your account:
GRANT SELECT ON mxs.y TO <account>;
Upvotes: 7