2016-11-10 208 views
3
SELECT e.pem_id   AS id, 
    e.pem_subject  AS subject, 
    e.pem_content  AS content, 
    e.pem_sent_date AS sentdate, 
    e.pem_ref_id  AS referenceid, 
    e.pem_from_usr_id AS userid, 
    NULL    AS misc, 
    (listagg(str.str_us_id, ', ') within GROUP(ORDER BY '') AS attachedusers FROM 
     proj_email_usrs eu LEFT OUTER JOIN st_register str ON 
     eu.pmu_str_id = str.str_id WHERE eu.pmu_pem_id = '26' GROUP BY '') 
FROM proj_email e 
WHERE e.pem_prj_id = '33' 
AND e.pmu_pem_id = '26' 
AND e.pem_status = 'S'; 

它扔誤差甲骨文LISTAGG子查詢

ORA-01722:無效數字

01722. 00000 - 「無效號碼」

*原因:指定的數無效。

*操作:指定一個有效的號碼。

+0

我假設後面的剔號並不真正在您的查詢中。 –

回答

4

我假設你想要一個這樣的查詢:

SELECT E.PEM_ID as Id, E.PEM_SUBJECT as Subject, E.PEM_CONTENT as Content, 
     E.PEM_SENT_DATE as SentDate, E.PEM_REF_ID as ReferenceId, 
     E.PEM_FROM_USR_ID as UserId, NULL as Misc, 
     (SELECT LISTAGG(STR.STR_US_ID, ', ') WITHIN GROUP (ORDER BY STR.STR_US_ID) 
     FROM PROJ_EMAIL_USRS EU LEFT OUTER JOIN 
      ST_REGISTER STR 
      ON EU.PMU_STR_ID = STR.STR_ID 
     WHERE EU.PMU_PEM_ID = E.PMU_PEM_ID -- Correlation clause 
     ) as AttachedUsers 
FROM PROJ_EMAIL E 
WHERE E.PEM_PRJ_ID = 33 AND E.PMU_PEM_ID = 26 AND E.PEM_STATUS = 'S' ; 

評論:

  • 添加了SELECTLISTAGG()之前。需要子查詢。
  • 刪除GROUP BY。不需要,因爲您希望子查詢始終返回一行。
  • 從常量中刪除可能是數字的單引號。只對字符串和日期常量使用單引號。
  • 向子查詢添加了關聯子句。
  • 將子列名稱移到子查詢之外,所以它在結果中被命名。
  • WITHIN GROUP添加了ORDER BY列。沒有必要,但合理地保持ID的順序。
+0

你讓我的一天:)謝謝......正常工作......你已經解釋了它值得嘉獎的原因。 – Emperor