---
title: "decode与case when比较"
author: "xiajava2011"
date: "2011-08-19T10:11:05Z"
tags: []
categories: ["数据库"]
slug: "decode-case-when"
draft: false
lastmod: "2011-08-19T10:13:44Z"
id: 1153068
url: "https://xiajava2011.iteye.com/blog/1153068"
---

decode只能做等值的，case when可以做区间的，decode能做到的，case when也能做到。

效率方面，个人觉得两者效率差不多。

但decode的语法要简单些，但它只能做等值的比较

case when end 能做条件的判断

```
select case when b.total_fee is null then 0 else b.total_fee end from t_pm_billing_stat b 
select a.area_name, decode(b.billing_amount,null,0 ,b.billing_amount) from t_pm_billing_stat b 
```