title: LISTAGG IN PL/SQL
body: <p>Help please find mistake in creating function which will return one row from list.</p>
  
  <pre><code>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 
  </code></pre>
  
  <p>The code return correct result.</p>
  
  <p>But the next dont return the same.</p>
  
  <pre><code>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;
  </code></pre>