I want to create a function that returns multiple varchar2 columns. his is what I have so far, but it errors on the execute immediate call.
FUNCTION FNC_LST_OUR(p_com_code varchar2,
p_from varchar2,
p_to varchar2
) return VARCHAR2 is
v_sql VARCHAR2(30000) := '';
v_sql2 VARCHAR2(30000) := '';
error_msg_tmp varchar2(255);
begin
v_sql := 'select s.com_code, s.p_code, count(*) as Num_SIMRP
from p_stest s
where s.com_code = ''' || p_com_code || '''
and s.s_status = ''ACTIVE''
and s.s_type like ''H%'' ';
if p_from is not null then
v_sql := v_sql || ' and s.p_code between ''' || p_from || ''' and ''' || p_to || '''';
end if;
v_sql := v_sql || ' group by s.com_code,s.p_code
having count(s.p_code)> 0 ';
EXECUTE IMMEDIATE v_sql INTO v_sql2 USING p_com_code; --> Error This Line
return v_sql2;
end;
I need it to return multiple columns like:
com_code | p_code | num_simrp
A | ADSWQ | 14
A | AQWSA | 8
A | DEWSQ | 10
A | SDERS | 45
A | DFDEW | 80
I must create the function in a package and inner join the result as part of a query.