我有一个过程,它接受2个参数格式:
i_rule_type:' val1',' val2',' val3'
i_geo:' val1',' val2',val3'
我知道他们正确进入,因为底部的if / else语句正常工作。当我对两个参数中的值进行硬编码或传入null时,查询可以正常工作。我可以说它在这种情况下正在运行,因为它需要一点时间才能完成并实际返回行。但是,当我传入参数时,它就像查询甚至没有运行一样 - 它立即完成并且没有任何错误就为空。我目前的怀疑是这些变量实际上并没有受到限制,但是我被卡住了。
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;