1. 程式人生 > >where 條件中 使用 instr 替代 in

where 條件中 使用 instr 替代 in

select  * from  expense  ee  where ee.pro_ype = processType  and ee.cost_type in ( SELECT tt.value FROM t_enum tt where  tt.enum_name = processType ) ;

processType 為傳進來的引數,相當於根據傳進來的值分別得到不同的查詢語句:

1.  select  * from  expense  ee where ee.pro_ype = 1 and ee.cost_type in ( 1,2) 

2.  select  * from  expense  ee  where ee.pro_ype = 1 and ee.cost_type in 

( 2) 

可用 instr 函式替代

select  * from  expense  ee where ee.pro_ype = processType  and  instr(costType,ee.cost_type)  = 1;   // costType 的內容是否包含了cost_type的值