11

次のクエリを実行すると:

 Select
  tm.product_id,
  listagg(tm.book_id || '(' || tm.score || ')',',')
    within group (order by tm.product_id) as matches
from
  tl_product_match tm 
where
  tm.book_id is not null 
group by
  tm.product_id

Oracle は次のエラーを返します。

 ORA-01489: result of string concatenation is too long

それが失敗する理由は、listagg 関数が、サポートされていない 4000 文字を超える値を連結しようとしていることです。

ここで説明されている別の例を見てきました- http://www.oracle-base.com/articles/misc/string-aggregation-techniques.phpしかし、それらはすべて関数または手順の使用を必要とします。

関数やストアド プロシージャを呼び出す必要がなく、標準の JDBC を使用して値を読み取ることができる純粋な SQL のソリューションはありますか?

私が抱えているもう1つの問題は、私が見たほとんどの文字列集約の例が、値をそのまま読み取る方法の例を示していることです。私の例では、最初に値を変更しています(つまり、2つの列を集約しています)。

4

3 に答える 3

6

xml関数を使用して、CLOBを返すことができます。JDBCはそれで問題ないはずです。

select tm.product_id, 
       rtrim(extract(xmlagg(xmlelement(e, tm.book_id || '(' || tm.score || '),')), 
               '/E/text()').getclobval(), ',')
  from tl_product_match tm
 where tm.book_id is not null 
 group by tm.product_id;

例:http ://sqlfiddle.com/#!4 / 083a2 / 1

于 2013-02-13T22:44:44.893 に答える
3

ネストされたテーブルを使用しないのはなぜですか?

set echo on;
set display on;
set linesize 200;

drop table testA;
create table testA
(
col1 number,
col2 varchar2(50)
);

drop table testB;
create table testB
(
col1 number,
col2 varchar2(50)
);

create or replace type t_vchar_tab as table of varchar2(50);

insert into testA values (1,'A');
insert into testA values (2,'B');

insert into testB values (1,'X');
insert into testB values (1,'Y');
insert into testB values (1,'Z');
commit;

-- select all related testB.col2 values in a nested table for each testA.col1 value
select a.col1, 
cast(multiset(select b.col2 from testB b where b.col1 = a.col1 order by b.col2) as t_vchar_tab) as testB_vals
from testA a;

-- test size > 4000
insert into testB
select 2 as col1, substr((object_name || object_type), 1, 50) as col2
from all_objects;
commit;

-- select all related testB.col2 values in a nested table for each testA.col1 value
select a.col1, 
cast(multiset(select b.col2 from testB b where b.col1 = a.col1 order by b.col2) as t_vchar_tab) as testB_vals
from testA a;

私はJavaの専門家ではありませんが、これはしばらく前からあり、Javaがネストされたテーブルから値を引き出すことができると確信しています。また、反対側で区切られた文字列をトークン化する必要はありません。

于 2013-02-14T19:04:14.983 に答える
0

ここで説明されている別の例を見てきました- http://www.oracle-base.com/articles/misc/string-aggregation-techniques.phpしかし、それらはすべて関数または手順の使用を必要とします。

いいえ、そうではありません。下にスクロールすると、pl/sql を必要としないいくつかのオプションが表示されます。

于 2013-02-13T22:12:01.180 に答える