본문 바로가기

JAVA/Oracle

오라클 - 답변형 게시판 쿼리 ( 부모글 지울 때 답변글에 '부모글이 삭제되었다'는 것을 써주기 위한 질의문

반응형

A

select no, b_ref, b_level, b_step from board order by b_ref desc, b_step; 


B

형식 : select rownum num, no, b_ref, b_level, b_step from (A);

질의 : select rownum num, no, b_ref, b_level, b_step from (select no, b_ref, b_level, b_step from board order by b_ref desc, b_step);


C

시작위치

형식 : select num from (B) where num = 5;

질의 : select num from (select rownum num, no, b_ref, b_level, b_step from (select no, b_ref, b_level, b_step from board order by b_ref desc, b_step)) where num = 5;


D

마지막위치

행번호가 C보다 크고 b_level 1인것

형식 : select min(num) from (B) where num > (C) and b_level = 1;

질의 : select min(num) from (select rownum num, no, b_ref, b_level, b_step from (select no, b_ref, b_level, b_step from board order by b_ref desc, b_step)) where num > (select num from (select rownum num, no, b_ref, b_level, b_step from (select no, b_ref, b_level, b_step from board order by b_ref desc, b_step)) where num = 5) and b_level <= 1;


E

본질의

형식 : select no from (B) where num between (C)+1 and (D)-1;

질의 : select no from (select rownum num, no, b_ref, b_level, b_step from (select no, b_ref, b_level, b_step from board order by b_ref desc, b_step)) where num between (select num from (select rownum num, no, b_ref, b_level, b_step from (select no, b_ref, b_level, b_step from board order by b_ref desc, b_step)) where num = 5)+1 and (select min(num) from (select rownum num, no, b_ref, b_level, b_step from (select no, b_ref, b_level, b_step from board order by b_ref desc, b_step)) where num > (select num from (select rownum num, no, b_ref, b_level, b_step from (select no, b_ref, b_level, b_step from board order by b_ref desc, b_step)) where num = 5) and b_level <= 1)-1;


** 진짜 질의

형식 : update board set del_p=1 where no in(E);

질의 : update board set del_p=1 where no in(select no from (select rownum num, no, b_ref, b_level, b_step from (select no, b_ref, b_level, b_step from board order by b_ref desc, b_step)) where num between (select num from (select rownum num, no, b_ref, b_level, b_step from (select no, b_ref, b_level, b_step from board order by b_ref desc, b_step)) where num = 5)+1 and (select min(num) from (select rownum num, no, b_ref, b_level, b_step from (select no, b_ref, b_level, b_step from board order by b_ref desc, b_step)) where num > (select num from (select rownum num, no, b_ref, b_level, b_step from (select no, b_ref, b_level, b_step from board order by b_ref desc, b_step)) where num = 5) and b_level <= 1)-1);


** 이제 이 질의문을 프로그램에 적용시키기

1. BoardDao 에 deleteBoard 에다가 질의문 써주고 변수처리 해준다 굵은글씨 3부분을..

2. 삭제하기전에 원래글의 정보를 저장해둔다. BoardVo 를 생성해서..

3. viewPage 의 listBoard.jsp 에가서 

<a href="detailBoard.do?no=${b.no }">${b.title } </a>  여기 밑에 추가해줌


이렇게

<c:if test="${b.del_p ==1 }">

<font color="hotPink" ><small>부모글이 삭제됨</small></font>

</c:if>


반응형