by 유환 [Oracle 기초] LIKE [2012.04.17 17:14:48]
-- 1. OR 조건
SELECT ~ FROM ~ WHERE ~
AND ( :v_state_cd IS NULL OR stat_cd = :v_state_cd )
;
-- 2. NVL 처리
SELECT ~ FROM ~ WHERE ~
AND NVL(stat_cd, 'x') LIKE :v_state_cd||'%'
;
-- 3. UNION ALL 처리
SELECT ~ FROM ~ WHERE ~
AND :v_state_cd IS NULL
UNION ALL
SELECT ~ FROM ~ WHERE ~
AND :v_state_cd IS NOT NULL
AND stat_cd = :v_state_cd
;
--4. 동적쿼리
sql := 'SELECT ~ FROM ~ WHERE ~';
IF v_state_cd IS NOT NULL THEN
sql := sql + ' AND stat_cd = :v_state_cd';
END IF;