the above example didn't compile... below example will compile
create or replace function f(p_a varchar2, p_b varchar2) return sys_refcursor
is
retval sys_refcursor;
report_query_a varchar2(4000) := 'select a , b , c from my_table where 1=1 ';
report_query_b varchar2(4000) := 'select a , b , c, d from my_table where 1=1 ';
report_query varchar2(4000);
begin
--determine the columns to return
if p_b is not null then
report_query := report_query_b;
else
report_query := report_query_a;
end if;
--add the filters to the report query
if p_a is not null then
report_query := report_query||' and a = '''||p_a||'''';
end if;
if p_b is not null then
report_query := report_query||' and b = '''||p_b||'''';
end if;
open retval for report_query;
return retval;
end;
/