We currently have a stored proc that needs to do the following:
If Query1 returns any results open a sys_refcursor cursor for that and return it back
else
open a cursor for Query2
Currently we are doing a count(*) on the from and where clauses of Query1 and use the count in a if-else stmt. However, this causes query1 to be executed twice. Is there a way to optimize this?
Open the cursor for query1 & perform the real query. Wrap it in a BEGIN .. END block & catch the no data found exception.
The query2 code will get run when there’s no data returned by query1.