2010-04-29 21 views
1

我已經選擇,如:wm_concat功能和小characer緩衝

select substr(account,1,4), currency, amount, module,count(*) quan, wm_concat(id) ids from all_transactions group by substr(account,1,4), currency, amount, module 

但有時COUNT(*),更多的則是600。在這種情況下,我得到: 「ORA-06502:PL/SQL:字符字符串緩衝區太小'

是否有任何方法保留所有記錄的wm_concat(id)? 因爲排除具有大COUNT(*)條目的此函數是出路。

+0

collect(id)可以使用,但我不能將其導出爲ex​​cel正確:( – Ruslan 2010-04-29 12:58:21

回答

3

問題可能是WM_CONCAT()試圖生成一個大於VARCHAR2數據庫端限制的字符串,我相信它是2000個字符。在PL/SQL代碼中,如果我記得正確,限制很大 - 32767。您可能需要將其分解爲多個查詢。首先,做你的總和

strAccount VARCHAR2(4); 
strCurrency all_transactions.currency%type; 
nAmount  all_transactions.amount%type; 
strModule all_transactions.module%type; 
nQuantity NUMBER; 

select substr(account,1,4), currency, amount, module, count(*) quan 
    into strAccount, strCurrency, nAmount, strModule, nQuantity 
    from all_transactions 
    group by substr(account,1,4), currency, amount, module 

然後步行一個光標分別獲得了名字和your're使用任何應用程序語言一起將它們連接起來。如果你的代碼是用PL/SQL它可能看起來像:

strNames VARCHAR2(32767); 

FOR aRow in (select id 
       from all_transactions 
       where substr(account, 1, 4) = strAccount and 
        currency = strCurrency and 
        amount = nAmount and 
        module = strModule 
       order by id) 
LOOP 
    strNames := strNames || aRow.id || ' '; 
END LOOP 

當然,這是不是世界上最優雅的解決方案的解決方案,但考慮到WM_CONCAT不在這裏實際可能會被卡住做的事情喜歡這個。

分享和享受。

+0

Jees,經過這麼多的努力,他甚至都沒有謝謝你,有些人...... – TrojanName 2011-10-04 15:01:41

+2

@BrianFenton:看到定義「無名英雄」徽章...... – 2011-10-05 16:51:44