The following code creates a filter that I successfully append to an existing sql statement.
DECLARE V_FILTER VARCHAR2(255);
begin
SELECT DISTINCT 'reserve reporting_unit_code' ||' IN (' ||
listagg ( chr(39) || uic || chr(39) , ',') within group (order by uic) || ')'
into v_FILTER
from ( select distinct uicf.uic
FROM OWSADHOC.ADHOC_UIC_FILTER UICF
INNER JOIN OWSADHOC.ADHOC_USER_ROLE UROLE
ON UICF.ROLE_NAME = UROLE.ROLE_NAME
inner join OWSADHOC.ADHOC_USER_DATA uname
on uname.USER_ID = UROLE.USER_ID
WHERE UROLE.ROLE_NAME in (:P_LoggedInUserRoles)
and uname.JASPER_ACCOUNT = :P_LoggedInUserName
)
;
DBMS_OUTPUT.PUT_LINE ('GENERATED FILTER: ' || V_FILTER);
end;
v_FILTER
is reserve reporting_unit_code IN ('86749')
This works fine when P_LoggedInUserRoles
has only one value. However, if I have a comma separated list in the variable, it is not working. I've tried defining expressionList as an array. PL/SQL doesn't compile using that method.
Is the expressionList constrained to the use of literal values if one has more than one value? I can't find that explicit statement in any manual, but I haven't been able to define the expressionList as a variable that is a collection of values.