我是一個新手,我需要一些建議,以解決我的問題 我創建了一個定義用戶太小聚合函數如:錯誤:ORA-06502 - PL/SQL:數字或值錯誤:字符串緩衝區時,使用用戶定義的函數
create type nvarAggregate as object
(
storedAtt nvarchar2(300),
static function ODCIAggregateInitialize (sctx IN OUT nvarAggregate) return NUMBER,
member function ODCIAggregateIterate (self IN OUT nvarAggregate, value IN nvarchar2) return NUMBER,
member function ODCIAggregateTerminate (self IN nvarAggregate, returnValue OUT nvarchar2, flags IN number) return NUMBER,
member function ODCIAggregateMerge (self IN OUT nvarAggregate, ctx2 IN nvarAggregate) return NUMBER
);
/
*****************************
create or replace type body nvarAggregate
is
static function ODCIAggregateInitialize (sctx IN OUT nvarAggregate) return NUMBER
is
begin
sctx:=nvarAggregate(NULL);
return ODCIConst.Success;
end;
member function ODCIAggregateIterate (self IN OUT nvarAggregate, value IN nvarchar2) return NUMBER
is
begin
self.storedAtt:=self.storedAtt||trim(value)||'; ';
return ODCIConst.Success;
end;
member function ODCIAggregateTerminate (self IN nvarAggregate, returnValue OUT nvarchar2, flags IN number) return NUMBER
is
begin
if trim(self.storedAtt)<>';' then
returnValue:=substr(trim(self.storedAtt),0,length(trim(self.storedAtt))-1);
else
returnValue:=NULL;
end if;
return ODCIConst.Success;
end;
member function ODCIAggregateMerge (self IN OUT nvarAggregate, ctx2 IN nvarAggregate) return NUMBER
is
begin
self.storedAtt:=self.storedAtt||substr(trim(ctx2.storedAtt),0,length(trim(ctx2.storedAtt))-1)||'; ';
return ODCIConst.Success;
end;
end;
/
**************************************
create or replace function nvarAgg(value IN nvarchar2) return nvarchar2 parallel_enable aggregate using nvarAggregate;
/
現在,當我在SQL語句中使用nvarAgg功能
select id,nvarAgg(iforField) from testtable group by id
我得到錯誤信息從Oracle:
ORA-06502 - PL/SQL: numeric or value error: character string buffer too small
你有任何解決方案嗎? 非常感謝
好吧,做任何ID連接值超過300個字符? (或300個字節,這取決於您的默認字符串語義) –
我試圖與NVARCHAR2(32767)的最大尺寸,但我仍然得到了同樣的結果。 –
聽起來就像聚合時只有太多數據。但對shreesha的回答發表評論表明它不會與varchar2錯誤。那麼你使用字符還是字節語義? (無論如何,如果你達到了32K,那就不重要了,我想)。即使它現在可行,未來的數據可能會超過它。 CLOB可能是要走的路。但也要確保你沒有聚合比你期望的更多的值 - 看起來不像你的示例查詢。 –