Thread: How to use an array string
Hi All,
I need help. I want to build a list of customers (custid) that has the word 'sam' in their fullname and store them to a text string (ResultList). Then on the second query, I want to select the customers with ID that matches the ID in the ResultList.
DECLARE
rec_set record;
s_result text;
ResultList text := '''';
BEGIN
rec_set record;
s_result text;
ResultList text := '''';
BEGIN
For rec_set IN SELECT CustID
FROM Customer where Fullname ~* ''(sam)''
LOOP
ResultList := ResultList || '''''''' || rec_set.CustID || '''''''' || '', '';
END LOOP;
FROM Customer where Fullname ~* ''(sam)''
LOOP
ResultList := ResultList || '''''''' || rec_set.CustID || '''''''' || '', '';
END LOOP;
END;
BEGIN
For rec_set IN SELECT Fullname, Address
/*from Customer where CustID in (''1220'', ''3452'', ''4112'', '''')*/
from Customer where CustID in (ResultList)
/*from Customer where CustID in (''1220'', ''3452'', ''4112'', '''')*/
from Customer where CustID in (ResultList)
END;
The problem is that the query can't find any match. Maybe because it compares a CustID with a string of values (ResultList). Does anybody have any suggestions on how I can get around this ? Does anybody know how to build an array string so I can store the cust id ?
Thanks,
Sam