1. 程式人生 > >mysql中case-when-then和oracle的decode函式

mysql中case-when-then和oracle的decode函式

mysql中case-when-then的用法
<select id="selectConType" resultType="hashmap">
    select DISTINCT
    case
        when con_type =1 then 'Layout'
        when con_type =2 then 'Menu and Button'
        when con_type =3 then 'Form'
        when con_type =4 then 'DataGrid and Tree'
        when con_type =5 then 'Window'
        when con_type =6 then 'Html'
        when con_type =7 then 'Table'
        when con_type =8 then 'Other'
        end as META_TYPE,CON_TYPE from
    FDES_FORM_CON order by CON_TYPE asc
</select>

oracle中decode()函式的用法
<select id="selectConType" resultType="hashmap">
    select DISTINCT
    decode(con_type,1,'Layout',2,'Menu and Button',3,'Form',4,'DataGrid and Tree',5,'Window',6,'Html',7,'table',8,'Other') META_TYPE
    , CON_TYPE from
    FDES_FORM_CON order by CON_TYPE asc
</select>