을 구현하는'20 질문에'-다음과 같 마법사를 데이터베이스에
-
09-06-2019 - |
문제
내가 찾는 것을 구현하는 데이터를 기반으로 마법사를 이 질문 나무 Oracle 데이터베이스에 저장된.최고의 스키마를 만들기 위해 사용하는 데이터베이스의 부분을 가동 가능한(i.e쉽게 추가하는 새로운 경로의 질문)희생 없이는 너무 많은 측면에서의 성능은?
해결책
를 구축할 수 있습니다 나무 구조를 사용하여 외국 열쇠를 참조하는 동 테이블("돼지의 귀"관계로 그것은 흔히 알려진).다음을 사용할 수 있습을 연결해 구문을 통과하는 나무입니다.여기에 간단한 예제:
SQL> create table qs
2 ( q_id integer primary key
3 , parent_q_id integer references qs
4 , parent_q_answer varchar2(1)
5 , q_text varchar2(100)
6* );
Table created.
SQL> insert into qs values (1, null, null, 'Is it bigger than a person?');
1 row created.
SQL> insert into qs values (2, 1, 'Y', 'Does it have a long neck?');
1 row created.
SQL> insert into qs values (3, 2, 'Y', 'It is a giraffe');
1 row created.
SQL> insert into qs values (4, 2, 'N', 'It is an elephant');
1 row created.
SQL> insert into qs values (5, 1, 'N', 'Does it eat cheese?');
1 row created.
SQL> insert into qs values (6, 5, 'Y', 'It is a mouse');
1 row created.
SQL> insert into qs values (7, 5, 'N', 'It is a cat');
1 row created.
SQL> commit;
Commit complete.
SQL> select rpad(' ',level*4,' ')||parent_q_answer||': '||q_text
2 from qs
3 start with parent_q_id is null
4 connect by prior q_id = parent_q_id;
RPAD('',LEVEL*4,'')||PARENT_Q_ANSWER||':'||Q_TEXT
------------------------------------------------------------------------------------------------------------------------------
: Is it bigger than a person?
Y: Does it have a long neck?
Y: It is a giraffe
N: It is an elephant
N: Does it eat cheese?
Y: It is a mouse
N: It is a cat
7 rows selected.
참고 어떻게 특별한 키워드 수준을 결정하는 데 사용될 수 있습 얼마나 나무 아래로 우리가 나가는 다음을 사용하여 들여쓰기를 보여주기 위해 데이터의 구조입니다.
제휴하지 않습니다 StackOverflow