title: Sum Listagg in a query
body: <p>I am trying to sum the values from the listagg query i made.</p>
  
  <p>Expected result should be like this</p>
  
  <pre><code>SELECT LEGAL_ENTITY_ID, SUM(0 + 0 + 0 + 1) as Grandtotals
  FROM V_VBA_DDCR_MAIN WHERE LEGAL_ENTITY_ID=6012346 AND ROWNUM=1
  GROUP BY LEGAL_ENTITY_ID
  
   |      LEGAL_ENTITY_ID | GRANDTOTALS 
  1|    6012346           | 1
  </code></pre>
  
  <p>My listagg goes like this </p>
  
  <pre><code>SELECT LISTAGG(NVL2(FLDNM,0,1) , '+ ') WITHIN GROUP (ORDER BY FLDNM) FROM LE_MERGE_DDC_MAPPING
  </code></pre>
  
  <p>the purpose of this query is to count the number of null fields in a row. I created a table containing the list of fields that needs to be checked for null values. </p>
  
  <p>Result :</p>
  
  <pre><code>    fld1 + fld2 + fld3 + fld4
  =
          0 + 0 + 0 + 1
  </code></pre>
  
  <p>So I wrote my query like this:</p>
  
  <pre><code>SELECT LEGAL_ENTITY_ID, SUM(SELECT LISTAGG(NVL2(FLDNM,0,1) , '+ ') WITHIN GROUP 
  (ORDER BY FLDNM) FROM LE_MERGE_DDC_MAPPING) as Grandtotals
  FROM V_VBA_DDCR_MAIN WHERE LEGAL_ENTITY_ID=6000132
  GROUP BY LEGAL_ENTITY_ID
  </code></pre>
  
  <p>However, I am getting an error ORA-00936: missing expression.
  I am not sure if Oracle allows you to do a sum of the listagg function.
  Any help is appreciated.</p>