在数据查询中有时候需要对数据进行判断,显示不同的值。
一、Oracle
例如:查询的字段值如果是委员本人,显示1,录入人员显示2,其他人员显示0.
select decode('12','委员本人','1','录入人员','2','0') from dual;
用java语言解释就是,这里字段值,用‘12’代替
if(字段值.equals("委员本人")){
1
}else if(字段值.equals("录入人员")){
2
}else{
0
}
二、 MySQL
同样的需求使用mysql中的 case when then来写的话就是:
select case '12'
when '委员本人' then 1
when '录入人员' then 2
else 0
end
from dual;