페이징기법 sql문

3 views
Skip to first unread message

angelsskin2

unread,
Feb 7, 2013, 3:25:33 AM2/7/13
to Hanhwatra...@googlegroups.com

** 페이징 처리 **

select *
from (
          select /*+ first_rows(20) */  /* 페이지크기(20) */
                     query.*, rownum rn
          from  (select *
                     from employees
                     where 1=1   /* 입력변수 조건  */
                     and 1=1 /* 입력변수 조건  */
                     order by employee_id) query    /* order by 가장 상세한 테이블의 PK  */
          where rownum <= (1 * 20+1)  /* 입력변수 : 페이지번호(1) * 페이지크기(20)+1 */
          )
where rn between (1-1)*20+1 and 20*1 ;
                            /* (:페이지번호(1)-1)*:페이지크기(20)+1 AND :페이지크기(20)*:페이지번호(1) */  


-- 2페이지 보는방법
select *
from (
          select /*+ first_rows(20) */  /* 페이지크기(20) */
/*first_rows(20)을 없애주면 다 읽어야 하기 때문에, 처리해야 하는 용량이 엄청나게 늘어난다.*/
                     query.*, rownum rn
          from  (select *
                     from employees
                     where 1=1   /* 입력변수 조건  */
                     and 1=1 /* 입력변수 조건  */
                     order by employee_id) query    /* order by 가장 상세한 테이블의 PK  */
          where rownum <= (2 * 20+1)  /* 입력변수 : 페이지번호(2) * 페이지크기(20)+1 */ -- 2로 바꾸었다.
          )
where rn between (2-1)*20+1 and 20*2 ; -- 2로 바꾸었다.
                            /* (:페이지번호(2)-1)*:페이지크기(20)+1 AND :페이지크기(20)*:페이지번호(2) */    -- 2로 바꾸었다.


-- 2페이지 보는방법

Reply all
Reply to author
Forward
0 new messages