I have a procedure that takes in 2 parameters formatted like so:
i_rule_type: 'val1', 'val2', 'val3'
i_geo: 'val1', 'val2', val3'
I know that they are coming in correctly, because the if/else statement at the bottom is working. When I hard code the values in or pass in null for both parameters, the query works. I can tell that it is running in the situation, because it takes a little time to complete and actually returns the rows. However, when I pass the parameters in, it's like the query is not even running - it finishes instantly and empty without any errors. My current suspicions are that the variables are not actually being bound, but I'm stuck.
PROCEDURE REPORT_PRC (i_rule_type IN VARCHAR2, i_geo IN VARCHAR2, results_out OUT sys_refcursor) IS
v_report_query VARCHAR2(800);
BEGIN
v_report_query := 'SELECT r.NAME as RULE_NAME, r.DESCRIPTION as DESCRIPTION, r.RULE_ID as RULE_ID, r.AUDIENCE as RULE_TYPE, g.NAME as GEO, count(l.rule_id) as LEADS_ROUTED, max(l.LEAD_ASSIGNMENT_END) as LAST_ROUTED, a.NAME as ATTRIBUTE
FROM rule r
LEFT OUTER JOIN LEAD_DETAILED_LOG l on r.RULE_ID = l.RULE_ID
LEFT OUTER JOIN GEO g on r.GEO_ID = g.GEO_ID
LEFT OUTER JOIN RULE_ATTRIBUTE ra on r.RULE_ID = ra.RULE_ID
LEFT OUTER JOIN ATTRIBUTE a on ra.ATTRIBUTE_ID = a.ATTRIBUTE_ID';
if i_geo IS NOT NULL OR i_rule_type IS NOT NULL then
v_report_query := v_report_query || ' WHERE';
end if;
if i_rule_type IS NOT NULL then
v_report_query := v_report_query || ' r.AUDIENCE in (:i_rule_type)';
end if;
if i_geo IS NOT NULL then
if i_rule_type IS NOT NULL then
v_report_query := v_report_query || ' AND';
end if;
v_report_query := v_report_query || ' g.NAME in (:i_geo)';
end if;
v_report_query := v_report_query || ' GROUP BY r.rule_id, r.NAME, r.DESCRIPTION, r.RULE_ID, r.AUDIENCE, l.RULE_ID, g.NAME, a.NAME ORDER BY r.NAME';
if i_geo IS NOT NULL AND i_rule_type IS NOT NULL then
OPEN results_out FOR v_report_query USING i_rule_type, i_geo;
elsif i_geo IS NOT NULL then
OPEN results_out FOR v_report_query USING i_geo;
elsif i_rule_type IS NOT NULL then
OPEN results_out FOR v_report_query USING i_rule_type;
else
OPEN results_out FOR v_report_query;
end if;
end REPORT_PRC;