by 끌루니 [SQL Query] 컬럼 검색 DECODE [2013.03.06 17:27:34]
-- 1. OR & use_concat 힌트 SELECT /*+ use_concat */ * FROM test_table WHERE (:search_condition = 'a_col' AND a_col = :search_text) OR (:search_condition = 'b_col' AND b_col = :search_text) OR (:search_condition = 'c_col' AND c_col = :search_text) ; -- 2. Union All SELECT * FROM test_table WHERE (:search_condition = 'a_col' AND a_col = :search_text) UNION ALL SELECT * FROM test_table WHERE (:search_condition = 'b_col' AND b_col = :search_text) UNION ALL SELECT * FROM test_table WHERE (:search_condition = 'c_col' AND c_col = :search_text) ; -- 3. Dynamic SQL -- Pl/SQL 에서 사용 예시. 자세한 사항은 아래 URL 참고 -- http://www.gurubee.net/article/19612 v_sql := 'SELECT * FROM test_table'; v_sql := v_sql || ' WHERE ' || search_condition || ' = :search_text'; OPEN record_set FOR v_sql USING search_text;