2015-10-16 3348 views
0

我有一個問題,我無法解決。我有這樣的說法:oracle listagg - 字符串連接的結果太長

SELECT account, 
    listagg(field1 || ', ') WITHIN 
GROUP (
     ORDER BY field1 
     ) AS field1 
FROM TABLE1 
GROUP BY account 

我得到一個錯誤:

ORA-01489: result of string concatenation is too long 01489. 00000 - "result of string concatenation is too long" *Cause: String concatenation result is more than the maximum size. *Action: Make sure that the result is less than the maximum size.

如何解決?我試圖做到這一點,但它並沒有幫助的SQL函數返回一個字符串必須符合的最高限額內,這是4000

SUBSTR(listagg(field1 || ', ') WITHIN 
GROUP (
     ORDER BY field1 
     ), 1, 500) AS field1 
+0

如果連接時間過長,那麼明顯的解決方案是不是將其截斷? –

回答

1

結果(現在的32K甲骨文12C如果max_string_size=extended)。

你不能用SUBSTR截斷它,因爲那時已經太晚了 - 這是LISTAGG函數本身引發的異常。

解決此問題的唯一方法是確保被連接的記錄數量受到限制 - 例如,對每個account返回的記錄數量設置最大上限,和/或截斷每個文件的長度field1本身。

+1

或使用'XMLAGG'。 –

+0

@Lalit,謝謝你是對的,只需要對應用程序進行一些更改。 –