col ConcatVal for a30
--■■■count関数で葉か判断1■■■
select Replace(SubStr(sys_connect_by_path(ConcatString,','),2),'-',',') as ConcatVal
from (select to_char(a) || '-' || to_char(b) || '-' || to_char(c) as ConcatString,
Row_Number() over(order by a,b,c) as Rank,
count(a) over() as MaxLevel
from 数値テーブル)
where Level = MaxLevel
start with Rank = 1
connect by Prior Rank = Rank-1;
--■■■count関数で葉か判断2■■■
select Replace(SubStr(sys_connect_by_path(ConcatString,','),2),'-',',') as ConcatVal
from (select to_char(a) || '-' || to_char(b) || '-' || to_char(c) as ConcatString,
Lag(RowID) over(order by a,b,c) as LagRowID,
count(a) over() as MaxLevel
from 数値テーブル)
where Level = MaxLevel
start with LagRowID is null
connect by Prior RowID = LagRowID;
--■■■Connect_by_IsLeafを使って葉か判断1(10g以降)■■■
select Replace(SubStr(sys_connect_by_path(ConcatString,','),2),'-',',') as ConcatVal
from (select to_char(a) || '-' || to_char(b) || '-' || to_char(c) as ConcatString,
Row_Number() over(order by a,b,c) as Rank
from 数値テーブル)
where Connect_by_IsLeaf = 1
start with Rank = 1
connect by Prior Rank = Rank-1;
--■■■Connect_by_IsLeafを使って葉か判断2(10g以降)■■■
select Replace(SubStr(sys_connect_by_path(ConcatString,','),2),'-',',') as ConcatVal
from (select to_char(a) || '-' || to_char(b) || '-' || to_char(c) as ConcatString,
Lag(RowID) over(order by a,b,c) as LagRowID
from 数値テーブル)
where Connect_by_IsLeaf = 1
start with LagRowID is null
connect by Prior RowID = LagRowID;