table1
| base_yyyy | test_cd |
| 2021 | aaa |
| 2021 | bbb |
table2
| base_yyyy | test_cd | test_state |
| 2021 | aaa | Y |
select a.base_yyyy, a.test_cd, b.test_state
from table1 a , table2 b
where a.base_yyyy = b.base_yyyy(+)
and a.test_cd = b.test_cd(+)
and b.test_state = ? --> 조회조건으로 씀. 값은 전체(null), Y,N,O 선택가능
table2 에는 데이터가 1건이라 전체로 조회 시 2건 데이터가 나와야 합니다.
talbe2 의 test_state 는 default 로 N 값으로 보여줍니다
도움 부탁드립니다. 꾸벅
WITH table1 AS
(
SELECT '2021' base_yyyy, 'aaa' test_cd FROM dual
UNION ALL SELECT '2021', 'bbb' FROM dual
)
, table2 AS
(
SELECT '2021' base_yyyy, 'aaa' test_cd, 'Y' test_state FROM dual
)
SELECT a.base_yyyy
, a.test_cd
, NVL(b.test_state, 'N') test_state
FROM table1 a
, table2 b
WHERE a.base_yyyy = b.base_yyyy(+)
AND a.test_cd = b.test_cd(+)
AND NVL(b.test_state, 'N') LIKE NVL(:v_st, '%')
;
감사합니다. like 앞뒤로 nvl 처리 하면 되는거였네요~ 좋은 하루 보내세요