我有这个CLOBAGG()
函数聚合我的数据。问题是我总是得到这种形式:
|14| |Something | | |1 | |Something | | |2 | |Something | | |3 | |Something | | |4 | |Something | | |5 | |Something | | |6 | |Something | | |7 | |Something | | |8 | |Something | | |9 | |Something | | |10| |Something | | |11| |Something | | |12| |Something | | |13| |Something | |
在这种情况下,数据无关紧要。我希望从1到14得到结果。我的功能有问题,我不知道是什么。
这是功能:
create or replace type clobagg_type as object
(
text clob,
static function ODCIAggregateInitialize(sctx in out clobagg_type) return number,
member function ODCIAggregateIterate(self in out clobagg_type, value in clob) return number,
member function ODCIAggregateTerminate(self in clobagg_type, returnvalue out clob, flags in number) return number,
member function ODCIAggregateMerge(self in out clobagg_type, ctx2 in
clobagg_type) return number
);
create or replace type body clobagg_type is
static function ODCIAggregateInitialize(sctx in out clobagg_type) return number is
begin
sctx := clobagg_type(null) ;
return ODCIConst.Success ;
end;
member function ODCIAggregateIterate(self in out clobagg_type, value in clob) return number is
begin
self.text := self.text || value ;
return ODCIConst.Success;
end;
member function ODCIAggregateTerminate(self in clobagg_type, returnvalue out clob, flags in number) return number is
begin
returnValue := self.text;
return ODCIConst.Success;
end;
member function ODCIAggregateMerge(self in out clobagg_type, ctx2 in
clobagg_type) return number is
begin
self.text := self.text || ctx2.text ;
return ODCIConst.Success;
end;
end;
我按如下方式调用该函数:
CREATE TABLE TEST_STEPS (
test_case_id NUMBER(9,0),
test_steps CLOB
);
INSERT INTO TEST_STEPS(test_case_id,test_steps)
select test_case_id , clobagg(activity || chr(10)) as test_steps
from ( select test_case_id
, clobagg(' |' || AKTIVITÄT_NR || ' |' || AKTIVITÄT_KÜRZEL || ' |' || AKTIVITÄT_BESCHREIBUNG || ' |' || AKTIVITÄT_ERWARTETES_ERGEBNIS|| ' |' || CHR(10)) as activity
from TEST_STEPS_ORDERED
group by test_case_id, TESTSCHRITT_NR
, CAST(TESTSCHRITT_BEZEICHNUNG AS varchar(600))
, CAST(TESTSCHRITT_BESCHREIBUNG AS varchar(600))
order by test_case_id, testschritt_nr
)
group by test_case_id
当我通过test_case_id订购数据ASC时,AKTIVITÄT_NR我从1到14得到AKTIVITÄT_NR,因此它正常工作但函数CLOBAGG()
的结果是:
|1 | |Something | | |14| |Something | | |13| |Something | | |12| |Something | | |11| |Something | | |10| |Something | | |9 | |Something | | |8 | |Something | | |7 | |Something | | |6 | |Something | | |5 | |Something | | |4 | |Something | | |3 | |Something | | |2 | |Something | |
表TEST_STEPS_ORDERED看起来像这样