---
title: "oracle函数备忘"
author: "wangbing9577"
date: "2014-12-29T10:06:01Z"
tags: []
categories: ["数据库"]
slug: "oracle"
draft: false
lastmod: "2014-12-29T10:06:38Z"
id: 2170792
url: "https://wangbing9577.iteye.com/blog/2170792"
---

nvl(exp1,exp2):
if exp1 is null, return exp2;
else if exp1 is not null,return exp1;
exp1和exp2的type必须一致或可隐式的转成一致，但可以是任意type。

nvl2(exp1,exp2,exp3):
if exp1 is not null, return exp2;
else if exp1 is null, return exp3;
exp1的type任意；exp2和exp3的type必须一致或可隐式的转成一致，但不能是long。

nullif(exp1,exp2):
if exp1=exp2, return null;
else if exp1!=exp2, return exp1;

coalesce(exp1,exp2,...expn)
返回第一个非null表达式的值；若所有表达式都为null，返回Null。

decode(exp,srch1,rst1,[srch2,rst2,...srchn,rstn,default]):
若exp=srch1,返回rst1,
若exp=srch2,返回rst2,
...
若exp=srchn,返回rstn,
若没有找到匹配值，返回default,
若没有default，返回null。
进行比较之前，会把exp和每个srch条件转成srch1的类型
            会把返回值转成rst1的类型，若rst1为null或char，返回varchar2.
decode中，null可以参加等值比较，若exp为null，则返回第一个srch为null的rst值。
最多250个表达式。


