- A (T_REF 정수 l_date 일)
- B (T_REF 정수 client_ref 정수)
- C (t_id 정수를 client_ref 정수)
및 매개 변수 (client_ref_ integer).
1) client_ref 연결 테이블 B의 행이있는 경우 (쿼리select b.t_ref from B b where b.client_ref = client_ref_
반환하는 모든 데이터), 내 쿼리 보면됩니다 :
나는 조건 테이블 A에서 데이터를 선택해야합니다 이 같은 :
select max(l_date) from A where t_ref in (select b.t_ref from B b where b.client_ref = client_ref_)
2) 쿼리가 위의 모든 데이터를 반환하는 경우, 내 쿼리가 다음과 같이 표시됩니다
을select max(l_date) from A where t_ref in (select c.t_id from C c where c.client_ref = client_ref_)
지금 내가 PLSQL 함수를 작성했습니다 :
select max(aa.l_date) into l_date from A aa where aa.t_ref in (select bb.t_ref from B bb where bb.client_ref = client_ref_);
if l_date is null then
select max(aa.l_date) into l_date from A aa where t_ref in (select t_id from C c where c.client_ref = client_ref_);
end if;
return l_date;
그것은 작동을하지만 테이블에게 2 번 호출하기 때문에, 좋은 생각이 아니다. 두 번째 호출을 피하고 하나의 쿼리에서이 작업을 수행 할 수 있습니까?
첫 번째 선택이 실패합니다. 테이블을 별칭으로 선택 쿼리에서 단일 a를 사용했습니다. max (a.l_date) into l_date – XING
죄송합니다. typinq 실수였습니다. 그러나 그것은 주요한 문제가 아닙니다. – user3533397