In Oracle I have a stored procedure that queries a table and writes 2 fields into variables. Problem is Oracle will throw an error when nothing is returned. Here is my code
SELECT COUNT (empno),Name
INTO empcount,empname
FROM lv_request_header
WHERE empno = emp
AND request_id = rqid
GROUP BY empname
Using NVL with a count still throws an error
ERROR at line 1: ORA-20000: lv_request_header not found ORA-06512: at line 13
The error you posted indicates that the problem is that the table
lv_request_headerdoes not exist or that the owner of the procedure does not have access to it. If a user other than the owner of the procedure owns this table, you likely need to qualify the table name with the schema name or to create a synonym for the object.In general, if you want to deal with a
SELECT ... INTOstatement that returns 0 rows, you’d need to specify what values you want your two local variables to have in that case. If you wantempcountto be 0 andempnameto be NULL, you could do something like this