2017-11-06 2 views
0

여기변환 SQL 92 내가 ANSI 92에 ANSI 89 SQL 문을 변환하려고

가있다 ((가) "(+)"에 "OUTHER 가입"transofrm을 의미) 코드 :

select a.*, p.price 
from article a, prices p 
where a.product_id = p.product_id(+) 
and trunc(sysdate) + 1 between a.date_from and date_to 
and trunc(sysdate) + 1 between p.date_from(+) and p.date_to(+); 

나는 (+) 왼쪽 또는 오른쪽에 의미 알고 가입하세요, 그것은 배치되는 possition의 따라하지만 난 마지막 줄을 변환하는 방법을 얻을 수 없다 ( and trunc(sysdate) + 1 between p.date_from(+) and p.date_to(+) )

지금까지, 나는 follwo를했다. ing :

select a.*, p.price 
from article a 
left join prices p 
on a.product_id = p.product_id 
where trunc(sysdate) + 1 between a.date_from and date_to 

그러나 마지막 조건을 변환하는 데는 단서가 없습니다.

누군가 도와 드릴 수 있습니까? 나는 각 테이블은 date_fromdate_to을 가지고 있으리라 믿고있어 당신이 모두 범위에 대한 비교하는 것을 의미하는 것이

+0

'왼쪽 결합'을 사용하면 더 이상 '(+)'이 필요하지 않습니다. 서로 다른 ansi92 조인에 대해 [흥미로운 이전 게시물] (https://stackoverflow.com/questions/38549/what-is-the-difference-between-inner-join-and-outer-join?rq=1) 너는 읽을 수 있었다. 또한,'왼쪽 결합 '의'on'에서'between' criteria를 사용할 수 있습니다. (거의 그런식이 아니지만) – LukStorms

+0

'''trunc (sysdate) + 1 ''p.date_from과 p.date_to;'? –

+0

@LukStorms : 나의 실수, 나는 내 시도에 "(+)"을 잊었다. 어쨌든, 기사는 훌륭하지만 이미 LEFT/RIGHT/INNER/FULL 조인의 차이점을 알고 있습니다. 난 그냥 ANSI 92 – mikcutu

답변

0

, 감사합니다. 이 경우 예제 쿼리에 a.을 남겨 두었으므로 추가했습니다. 물론 ...

당신이 where 절에

and trunc(sysdate) + 1 between p.date_from and p.date_to 

를 추가한다면 명백한 어려움, 그 다음 어떤 "생성 NULL의"되는 기록을 그건 당신이 의미가없는 것입니다 경우 조정 주시기 그 조건으로 잘못 취급 될 것입니다. p의 날짜 범위 검사가 틀림없이 정말 조건을 가입하지 않기 때문에 그래서 그 대신 당신은 외부 조인 조건

select a.*, p.price 
    from   article a 
     left join prices p 
    on a.product_id = p.product_id 
    and trunc(sysdate) + 1 between p.date_from and p.date_to 
where trunc(sysdate) + 1 between a.date_from and a.date_to 

의미 적이 해킹의 비트가에 추가 할 수 있습니다; 그러나 이것은 "외부"의미를 조건에 적용합니다. 다른 더 명시 적 옵션은

select a.*, p.price 
    from   article a 
     left join prices p 
    on a.product_id = p.product_id 
where trunc(sysdate) + 1 between a.date_from and a.date_to 
    and (trunc(sysdate) + 1 between p.date_from and p.date_to 
     or p.product_id is null) 

이 (당신은 or 드롭 그냥 그런 between coalesce(p.date_from, trunc(sysdate)) and coalesce(p.date_to, trunc(sysdate)+2)) 또는 무언가를 말할 수있을 것입니다, 그러나 이것은 단지 generated- NULL 기록이 그 값에 대한 NULL있을 것이라고 가정 - 즉 prices 레코드의 실제 열은 NULL입니다.