所以我试图利用LISTAGG()函数来简单地构建一个逗号分隔的列表以在基础查询中使用。列表生成工作正常,我只是为了调试目的应用了一个输出,我可以看到我的列表应该是这样的:
值:'AB','AZ','BC','CA','CT','DC','FL','FO','GA','IL','KS','MA', 'MB','ME','MN','MS','MT','NB','NC','NL','NOVA SCOTIA','NS','NT','NU',' NY','ON','ONTARIO','OR','PE','QC','QUEBEC','QUEBEC','SASKATCHEWAN','SK','TX','VT','WA' ,'YT'
当我尝试将此列表变量传递给我的查询时,只是想看看是否有任何东西会回来,什么都不会回来,但是如果我从上面(原样)复制/过去的省/州列表而不是在我的where 子句,我得到一个结果。我究竟做错了什么?
DECLARE
v_PROVINCE varchar2(500);
v_results varchar2(1000);
BEGIn
dbms_output.enable(1000000);
Select '''' || LISTAGG(STATE, ''',''') WITHIN GROUP (ORDER BY STATE) || '''' PROV
INTO v_PROVINCE
from (Select distinct STATE from ADDRDATA where STATE IS NOT NULL);
DBMS_OUTPUT.PUT_LINE('VALUES: ' || v_PROVINCE);
Select CITY
INTO v_results
from VWPERSONPRIMARYADDRESS
where state in (v_Province)
AND ROWNUM <= 1;
DBMS_OUTPUT.PUT_LINE(v_results);
END;
/