위의 방법은 구현은 하기 쉬우나 DBMS 콜이 너무 많이 일어납니다. 저도 카테고리때문에 위랑 비슷하게 작성하였다가 엔코아 홈페이지에서 SQL 한 문장으로 끝내는 것을 보았는데 다음과 같이 SELF OUTER JOIN을 이용하여 끝내는 것을 보았습니다.

다음은 엔코아홈페이지에서 가지고 온 해결방안입니다.

1.sample 테이블 생성

create table test_ri (t_pk number, title varchar2(10), t_fk number);

2.sample data

insertinsert into test_ri values( 1 , 'T0', null);
insert into test_ri values ( 2 , 'T01' , 1);
insert into test_ri values( 3 , 'T02' , 1);
insert into test_ri values( 4 , 'T011' , 2);
insert into test_ri values( 5 , 'T012' , 2);
insert into test_ri values( 6 , 'T021' , 3);
insert into test_ri values( 7 , 'T1', null);

3.순전개와 역전개를 위한 최적화를 위한 인덱스 생성
create unique index test_ri_pk on test_ri (t_pk);
create unique index test_ri_fk on test_ri(t_fk,t_pk);

4.모범답안SQL
select a4.title||decode(a4.title,null,null,'/')||
a3.title|| decode(a3.title,null,null,'/')||
a2.title|| decode(a2.title,null,null,'/')||
a1.title Title
from test_ri a1, test_ri a2, test_ri a3, test_ri a4
where a1.t_fk = a2.t_pk(+) and a2.t_fk = a3.t_pk(+)
and a3.t_fk = a4.t_pk(+) order by 1;

Title
-------------------------------------------------
T0
T0/T01
T0/T01/T011
T0/T01/T012
T0/T02
T0/T02/T021
T1

'Interesting > TIPTECH' 카테고리의 다른 글

.NET Data Providers  (3) 2007.04.25
OLE DB Providers  (1) 2007.04.25
옥션에서 기회를 잡는 방법, 오픈마켓에서 기회 잡는 법  (0) 2007.02.26
오픈마켓  (1) 2007.02.26
오픈마켓의 특징 파악, 틈새로 적극 공략  (1) 2007.02.26

+ Recent posts