쿼리문에서 if문 질문이요! 채택완료
드래곤된다
10년 전
조회 3,039
예문쿼리에요.
a테이블에 id와 b테이블에 tel을 불러오는데 공통키로 cd를 가지고있어요.
</p><p>select </p><p> a.id</p><p><span style="font-size: 14.6666669845581px; line-height: 1.5;"> ,b.tel</span></p><p><span style="font-size: 11pt; line-height: 1.5;">from</span></p><p><span style="font-size: 11pt; line-height: 1.5;"></span><span style="font-size: 14.6666669845581px; line-height: 1.5;"> </span><span style="font-size: 11pt; line-height: 1.5;">table1 a</span></p><p><span style="font-size: 11pt; line-height: 1.5;"></span><span style="font-size: 14.6666669845581px; line-height: 1.5;"> </span><span style="font-size: 11pt; line-height: 1.5;">,table2 b</span><span style="font-size: 11pt; line-height: 1.5;"></span></p><p><span style="font-size: 11pt; line-height: 1.5;">where</span></p><p><span style="font-size: 11pt; line-height: 1.5;"></span><span style="font-size: 14.6666669845581px; line-height: 1.5;"> a.id='id'</span></p><p><span style="font-size: 11pt; line-height: 1.5;"></span><span style="font-size: 14.6666669845581px; line-height: 1.5;"> </span><span style="font-size: 11pt; line-height: 1.5;">and a.cd =</span></p><p><span style="font-size: 11pt; line-height: 1.5;"></span><span style="font-size: 14.6666669845581px; line-height: 1.5;"> </span><span style="font-size: 11pt; line-height: 1.5;"></span><span style="font-size: 14.6666669845581px; line-height: 1.5;"> </span><span style="font-size: 11pt; line-height: 1.5;">case</span></p><p><span style="font-size: 11pt; line-height: 1.5;"></span><span style="font-size: 14.6666669845581px; line-height: 1.5;"> </span><span style="font-size: 11pt; line-height: 1.5;"></span><span style="font-size: 14.6666669845581px; line-height: 1.5;"> </span><span style="font-size: 11pt; line-height: 1.5;"></span><span style="font-size: 14.6666669845581px; line-height: 1.5;"> </span><span style="font-size: 11pt; line-height: 1.5;">when</span></p><p><span style="font-size: 11pt; line-height: 1.5;"></span><span style="font-size: 14.6666669845581px; line-height: 1.5;"> </span><span style="font-size: 11pt; line-height: 1.5;"></span><span style="font-size: 14.6666669845581px; line-height: 1.5;"> </span><span style="font-size: 11pt; line-height: 1.5;"></span><span style="font-size: 14.6666669845581px; line-height: 1.5;"> </span><span style="font-size: 11pt; line-height: 1.5;"></span><span style="font-size: 14.6666669845581px; line-height: 1.5;"> </span><span style="font-size: 11pt; line-height: 1.5;">a.cd = b.cd</span></p><p><span style="font-size: 11pt; line-height: 1.5;"></span><span style="font-size: 14.6666669845581px; line-height: 1.5;"> </span><span style="font-size: 11pt; line-height: 1.5;"></span><span style="font-size: 14.6666669845581px; line-height: 1.5;"> </span><span style="font-size: 11pt; line-height: 1.5;"></span><span style="font-size: 14.6666669845581px; line-height: 1.5;"> </span><span style="font-size: 11pt; line-height: 1.5;">then</span></p><p><span style="font-size: 11pt; line-height: 1.5;"></span><span style="font-size: 14.6666669845581px; line-height: 1.5;"> </span><span style="font-size: 11pt; line-height: 1.5;"></span><span style="font-size: 14.6666669845581px; line-height: 1.5;"> </span><span style="font-size: 11pt; line-height: 1.5;"></span><span style="font-size: 14.6666669845581px; line-height: 1.5;"> </span><span style="font-size: 11pt; line-height: 1.5;"></span><span style="font-size: 14.6666669845581px; line-height: 1.5;"> </span><span style="font-size: 11pt; line-height: 1.5;">d.cd</span></p><p><span style="font-size: 11pt; line-height: 1.5;"></span><span style="font-size: 14.6666669845581px; line-height: 1.5;"> </span><span style="font-size: 11pt; line-height: 1.5;"></span><span style="font-size: 14.6666669845581px; line-height: 1.5;"> </span><span style="font-size: 11pt; line-height: 1.5;"></span><span style="font-size: 14.6666669845581px; line-height: 1.5;"> </span><span style="font-size: 11pt; line-height: 1.5;">else</span></p><p><span style="font-size: 11pt; line-height: 1.5;"></span><span style="font-size: 14.6666669845581px; line-height: 1.5;"> </span><span style="font-size: 11pt; line-height: 1.5;"></span><span style="font-size: 14.6666669845581px; line-height: 1.5;"> </span><span style="font-size: 11pt; line-height: 1.5;"></span><span style="font-size: 14.6666669845581px; line-height: 1.5;"> </span><span style="font-size: 11pt; line-height: 1.5;"></span><span style="font-size: 14.6666669845581px; line-height: 1.5;"> </span><span style="font-size: 11pt; line-height: 1.5;">null</span></p><p><span style="font-size: 11pt; line-height: 1.5;"></span><span style="font-size: 14.6666669845581px; line-height: 1.5;"> </span><span style="font-size: 11pt; line-height: 1.5;"></span><span style="font-size: 14.6666669845581px; line-height: 1.5;"> </span><span style="font-size: 11pt; line-height: 1.5;">end</span><span style="font-size: 11pt; line-height: 1.5;"></span></p><p>
이런식으로 if문을 줬는데요.
a테이블의 cd랑 b테이블의 cd가 있을땐 잘 나오는데요.
a테이블에 cd가 없을때도 있어요. 그래서 a테이블의 cd가 null허용이고요.
그래서 a.cd와 b.cd가 맞는게 없다면 a.cd is null 이렇게 줘야 널값을 찾게하는데 =를 빼면 문법오류가나버려요...
nvl써도 반환값을 정해야하는데 이미 =가 있어서 작성하고나면 a.cd = is null 이렇게 되어버려요.
if문에서 널값을 선택하는 방법이 없을까요...?
댓글을 작성하려면 로그인이 필요합니다.
답변 1개
답변을 작성하려면 로그인이 필요합니다.
로그인