The following code block will sometimes error with "ORA-01403: NO DATA FOUND". In the first query, I retrieve data stored in a table on another database, and I store that data into a temporary table. In the second query, I select the data out of the temporary table INTO a local variable. I have to do this because one of the fields is a CLOB and it is not possible to select a CLOB into a local variable across a database link.
-- insert clob from remote database into temp table across database link
-- it will be deleted upon implicit commit when the report ends;
INSERT INTO tmp_xml_result
SELECT add_id, site_cd, result_txt
FROM vw_add_result@ADifferentServer
WHERE add_id = p_add_id
AND site = p_site;
-- now that clob is local, we can select it into a variable
SELECT xml
INTO v_xml
FROM tmp_xml_result
WHERE id = p_add_id
AND site = p_site;
This block does not always error. When it does error, the second query throws NO DATA FOUND.
How can I adjust this code block so that it never results in a "ORA-01403: NO DATA FOUND" error? I know I can wrap the block in a BEGIN / EXCEPTION WHEN NO_DATA_FOUND... / END block, but the ideal solution will return the contents of the temporary table once they are available.
My environments use "Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production".