Return query based on condition
494124May 24 2007 — edited May 25 2007I'm trying to create a report region that returns results based on which table the data is stored. I'm using the type SQL Query(PL/SQL function body returning SQL query). I do a select to the first set of tables if the data is not there then it will do a select on the other set of tables. Each query will work find alone. But one query will not work when I use the condition IF Else return query.
Does anybody know how I can accomplish this?
Here is the Query:
declare
v_cnt number;
begin
select count(*) into v_cnt from image_repo_images im, image_repo_lookup il
where im.document_id_type = il.lookup_code
and il.lookup_type = 'DOCUMENT_TYPE'
and il.lookup_code = 1
and im.document_id = :P1_FILE_DLN;
if v_cnt > 0 then
return 'select distinct il.meaning, im.document_id, im.system_entry_date,im.batch_type,im.document_id_type
from image_repo_images im, image_repo_lookup il
where im.document_id = :P1_FILE_DLN
and im.document_id_type = il.lookup_code
and il.lookup_type = ''DOCUMENT_TYPE''
and il.lookup_code = 1;';
else
return 'select ''DLN'', dln, null e_date,null bt,null tp from income_tax_return_images where dln = :P1_FILE_DLN';
end if;
end;
Looks rather straight forward to me.
I get this error:
report error:
ORA-20001: Error fetching column value: ORA-01403: no data found
Any help will be appreciated.