시소당
가장 효율적인 MAX값처리를 위해 Index된 컬럼을 이용한다.
예) select stock_q
from GFLM600 a
where io_date = (select max(io_date)
from GFLM600 b
where b.car_code = :value1
and b.box_code = :value2
and a.car_code = b.car_code
and a.box_code = b.box_code); 2번 테이블을 읽어야 한다.
(개선안)
 select /*+ index_desc(a GFLM600_PK) :car_code + box_code + io_date */ stock_q
from GFLM600 a
where car_code = :value1
and box_code = :value2
and rownum = 1;
 max-min에서 sql분리
반드시 두개의 SQL문을 합쳐서 수행해야 좋은 성능을 얻는 것은 아니다. 다음의 경우는 분리하여 수행할 때 보다 만족한 성능을 얻는 경우이다.
- THISEQPM : THISEQPM_X1 = EQPMDEPT + EQPMPART + EQPMROOM
select (max(eqpmroom) – min(eqpmroom)) + 1 into :nextroom
from thiseqpm
where eqpmdept = :value1
and eqpmpart = :value2;
<개선안1> : Max, Min의 분리
Select /*+ index_desc (thiseqpm thiseqpm_x1) */
Eqmproom into max_room
From thiseqpm
Where eqpmdept = :value1 and eqpmpart = :value2
And rownum=1;
Select /*+ index_asc (thiseqpm thiseqpm_x1) */
Eqmproom into min_room
From thiseqpm
Where eqpmdept = :value1 and eqpmpart = :value2
And rownum=1;
<개선안2> In-line View를 이용하여 하나의 SQL로 작성
 select /*+ index_asc(a thiseqpm_x1) */ inv.max_room – a.eqpmroom + 1
from (select /*+ index_desc(thiseqpm thisqpm_x1) */ eqpmroom as max_room
from thisqpm
where eqpmdept = :value1
and eqpmpart = :value2
and rownum = 1) inv,
thiseqpm a
where eqpmdept = :value1
and eqpmpart = :value2
and rownum = 1;
 현재일자를 where에 넣고싶은 경우는 varchar2로 잡으면 편리하다.
To_char(sysdate,’yyyymmdd’)