2
我有這個clobagg功能:如何使CLOBAGG函數對結果進行排序?
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 or replace function clobagg(input clob) return clob
deterministic
parallel_enable
aggregate using clobagg_type;
/
但問題是,我得到的數據不正確的順序。你能幫助我,告訴我如何實現正確的秩序?我需要clobagg函數,因爲listagg和其他可以返回4000字節,在我的情況下,這是不夠的。
下面是該查詢:
CREATE TABLE GO_PRJ_SACHV7.TEST_STEPS1 (
test_case_id NUMBER(9,0),
activity CLOB
);
INSERT INTO GO_PRJ_SACHV7.TEST_STEPS(test_case_id, activity)
select test_case_id, clobagg(activity1)
from (
select
testschrit.testfall_id as test_case_id,
TESTSCHRITT_NR,
CHR(10) || 'h2.' || TESTSCHRITT_NR || ' ' ||
CAST(TESTSCHRITT_BEZEICHNUNG AS varchar(800)) || CHR(10) ||
CAST(TESTSCHRITT_BESCHREIBUNG AS varchar(800)) || CHR(10) ||
CAST(testschrit.TESTSCHRITT_BESCHREIBUNG AS varchar(800)) ||
'||AKTIVITÄT_NR' || '||AKTIVITÄT_KÜRZEL' || '||AKTIVITÄT_BESCHREIBUNG' ||
'||AKTIVITÄT_ERWARTETES_ERGEBNIS||' || CHR(10) ||
clobagg(
' |' || aktiv.AKTIVITÄT_NR || ' |' || aktiv.AKTIVITÄT_KÜRZEL || ' |' ||
aktiv.AKTIVITÄT_BESCHREIBUNG || ' |' ||
aktiv.AKTIVITÄT_ERWARTETES_ERGEBNIS || ' |' || CHR(10)
) as activity1
FROM
GO_PRJ_SACHV7.TESTFALLBESCHREIBUNG tfb,
GO_PRJ_SACHV7.TESTSCHRITTE testschrit,
GO_PRJ_SACHV7.AKTIVITÄTEN aktiv
WHERE testschrit.testfall_id = tfb.testfall_id(+)
AND testschrit.TESTSCHRITT_ID=aktiv.TESTSCHRITT_ID (+)
Group by
testschrit.testfall_id,
testschrit.testschritt_id,
testschrit.TESTSCHRITT_NR,
CAST(TESTSCHRITT_BEZEICHNUNG AS varchar(600)),
CAST(TESTSCHRITT_BESCHREIBUNG AS varchar(600))
order by testschrit.testfall_id, TESTSCHRITT_NR
)
group by test_case_id;
我嘗試「活動」列添加到表中以正確的順序。爲了這一刻,我可以添加到表中,但隨機順序。當我通過aktiv.AKTIVITÄT_NR嘗試訂單數據時,我也必須將此字段添加到我的羣組,並且這會破壞我的分組。
您可以向我們發送您的查詢嗎?你的數據是什麼?你有什麼?你能指望什麼? –
我嘗試按照正確的順序將活動列添加到表中。爲了這一刻,我可以添加到表中,但隨機順序。當我嘗試通過aktiv.AKTIVITÄT_NR嘗試訂單數據時,我還必須將此字段添加到我的組中,這會破壞我的分組。對不起,這很多部分。如果您願意,我可以通過電子郵件向您發送所有查詢 – Greg
您在查詢中使用了'clobagg()'兩次;都是按照你不喜歡的順序產生輸出,或者只是外部輸出? –