帮助请在创建函数时发现错误,该函数将从列表中返回一行。
SELECT listagg(' ' || V_RECEIVING_LIST.DOCUMENT_NUMBER || CHR(13))
WITHIN GROUP (ORDER BY V_RECEIVING_LIST.DOCUMENT_NUMBER)
FROM svc.claim_detail, tbc.v_receiving_list
WHERE claim_detail.id_claim = 334455
AND V_RECEIVING_LIST.ID_RECEIVING_LIST = CLAIM_DETAIL.ID_RECEIVING_LIST
代码返回正确的结果。
但下一个不会返回相同的。
DECLARE
scodes VARCHAR2 (4000);
BEGIN
SELECT (LISTAGG(' ' || RECEIVING_LIST.DOCUMENT_NUMBER || CHR(13))
WITHIN GROUP (ORDER BY RECEIVING_LIST.DOCUMENT_NUMBER))
INTO scodes
FROM svc.claim_detail, tbc.v_receiving_list
WHERE claim_detail.id_claim = 334455
AND RECEIVING_LIST.ID_RECEIVING_LIST = CLAIM_DETAIL.ID_RECEIVING_LIST;
DBMS_OUTPUT.PUT_LINE(scodes);
END;
答案 0 :(得分:0)
SQL> select * from V_RECEIVING_LIST ;
DOCUMENT_NUMBER ID_RECEIVING_LIST
--------------- --------------------
1 a
1 a
2 b
SQL> select * from claim_detail ;
ID_CLAIM ID_RECEIVING_LIST
---------- --------------------
123 a
123 a
124 b
SQL> DECLARE
2 scodes VARCHAR2 (4000);
3 BEGIN
4 SELECT (LISTAGG(' '|| v_receiving_list.DOCUMENT_NUMBER || CHR(13))
5 WITHIN GROUP (ORDER BY v_receiving_list.DOCUMENT_NUMBER))
6
7 INTO scodes
8 FROM claim_detail, v_receiving_list
9 WHERE claim_detail.id_claim = 123
10 AND v_receiving_list.ID_RECEIVING_LIST = CLAIM_DETAIL.ID_RECEIVING_LIST;
11
12
13 DBMS_OUTPUT.PUT_LINE('The output is '||scodes);
14 END;
15 /
1e output is 1
PL/SQL procedure successfully completed.