by 끌루니 [SQL Query] 컬럼 검색 DECODE [2013.03.06 17:27:34]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | -- 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 참고 v_sql := 'SELECT * FROM test_table' ; v_sql := v_sql || ' WHERE ' || search_condition || ' = :search_text' ; OPEN record_set FOR v_sql USING search_text; |