COALESCE NVL NVL2 DECODE
1 COALESCE
語法:COALESCE(expr1, expr2, ..., exprn) n>=2
作用:COALESCE returns the first non-null expr in the expression list. You must specify at least
two expressions. If all occurrences of expr evaluate to null, then the function returns
null.
COALESCE用於返回第一個非空的表達式.表達式只是兩個.如果所有的表達式為null,則返回null.
COALESCE(expr1, expr2)等價于 CASE WHEN expr1 IS NOT NULL THEN expr1 ELSE expr2 END
例子:
SELECT product_id, list_price, min_price,
COALESCE(0.9*list_price, min_price, 5) "Sale"
FROM product_information
WHERE supplier_id = 102050
ORDER BY product_id;
2 NVL
語法:NVL(expr1,expr2)
NVL lets you replace null (returned as a blank) with a string in the results of a query. If
expr1 is null, then NVL returns expr2. If expr1 is not null, then NVL returns expr1.
NVL 如果expr1為空,則返回expr2,不為空,就返回expr1.
例子:
SELECT last_name, NVL(TO_CHAR(commission_pct), 'Not Applicable') commission
FROM employees
WHERE last_name LIKE 'B%'
ORDER BY last_name;
3 NVL2
語法:NVL2(expr1,expr2,expr3)
作用:NVL2 lets you determine the value returned by a query based on whether a specified
expression is null or not null. If expr1 is not null, then NVL2 returns expr2. If expr1 is
null, then NVL2 returns expr3.
如果expr1的值為空,則返回expr2,不為空則返回expr3.
SELECT last_name, salary,
NVL2(commission_pct, salary + (salary * commission_pct), salary) income
FROM employees
WHERE last_name like 'B%'
ORDER BY last_name;
4 DECODE
語法:DECODE(expr,search1,result1,search2,result2...searchN,resultN,default)
作用:DECODE compares expr to each search value one by one. If expr is equal to a search,
then Oracle Database returns the corresponding result. If no match is found, then
Oracle returns default. If default is omitted, then Oracle returns null.
比較expr和search的值,如果相等,則返回result,否則返回default.
就是說如果expr等於search1,則返回result1的值,等於search2,則返回result2...如果都不滿足就返回default值.
例子:
SELECT product_id,
DECODE (warehouse_id, 1, 'Southlake',
2, 'San Francisco',
3, 'New Jersey',
4, 'Seattle',
'Non domestic') "Location"
FROM inventories
WHERE product_id < 1775
ORDER BY product_id, "Location";
COALESCE NVL NVL2 DECODE的更多相关文章
- oracle之nvl,nvl2,decode
oracle sql常用查询nvl,nvl2,decode区别及使用方法 1,NVL( E1, E2) 如果E1为NULL,则NVL函数返回E2的值,否则返回E1的值,如果两个参数都为NULL ,则返 ...
- 浅析ORACLE中NVL/NVL2/DECODE/CASE WHEN的用法
使用NVL的时候只能对值进行是否为空的判断,基本语法是NVL( 值1, ,结果2).它的功能是如果值1为空,则此函数返回结果2,不为空的话直接输出值1(如果两个参数都为空,那么还是返回空): NVL2 ...
- Oracle中的COALESCE,NVL,NVL2,NULLIF函数
http://jingyan.baidu.com/article/fa4125acaf898e28ac7092b9.html
- oracle几个函数整理 DECODE() NVL NVL2 NULLIF Coalesce(转)
DECODE() decode()函数简介: 主要作用:将查询结果翻译成其他值(即以其他形式表现出来,以下举例说明): 使用方法: Select decode(columnname,值1,翻译值1,值 ...
- SQL Fundamentals || Single-Row Functions || 通用函数 General function || (NVL,NVL2,NULLIF,DECODE,CASE,COALESCE)
SQL Fundamentals || Oracle SQL语言 SQL Fundamentals: Using Single-Row Functions to Customize Output使用单 ...
- NVL NVL2 COALESCE NULLIF decode
NVL(EXPR1,EXPR2)NVL2(EXPR1,EXPR2,EXPR3)NULLIF(EXPR1,EXPR2)COALESCE(EXPR1,,..,EXPRn)decode --------NV ...
- oracle group by rollup,decode,grouping,nvl,nvl2,nullif,grouping_id,group_id,grouping sets,RATIO_TO
干oracle 047文章12当问题,经验group by 声明.因此邂逅group by rollup,decode,grouping,nvl,nvl2,nullif,RATIO_TO_REPOR ...
- oracle NVL,NVL2,NULLIF,COALESCE
Oracle中函数以前介绍的字符串处理,日期函数,数学函数,以及转换函数等等,还有一类函数是通用函数.主要有:NVL,NVL2,NULLIF,COALESCE,这几个函数用在各个类型上都可以. 下面简 ...
- Oracle NVL 函数 nvl nvl2
Oracle中函数以前介绍的字符串处理,日期函数,数学函数,以及转换函数等等,还有一类函数是通用函数.主要有:NVL,NVL2,NULLIF,COALESCE,这几个函数用在各个类型上都可以. 下面简 ...
随机推荐
- PyQt4关闭最大化最小化取消双击最大化
self.setWindowFlags(Qt.Window | Qt.WindowTitleHint | Qt.WindowCloseButtonHint | Qt.CustomizeWindowHi ...
- EOS/普元:概述:中国IT业的悲哀
公司引入了普元的EOS作为公司的基础架构平台,今后的所有项目将逐步向EOS的迁移,但对EOS的研究又让我不得不说出以下话: 1.EOS确实够简单,但未免简单过了头:从语言层面看EOS 因为EOS将成为 ...
- AngularJs之ng-repeat的用法
可参考文章:http://blog.csdn.net/renfufei/article/details/43061877 ng-repeat信息展示的核心: [1]异步读取数据源 works,见代码一 ...
- poj 1611(并查集)
http://poj.org/problem?id=1611 题意:有个学生感染病毒了,只要是和这个学生接触过的人都会感染,而和这些被感染者接触的人,也会被感染,现在给定你一些协会的人数,以及所在学生 ...
- php xdebug配置
2015年11月27日 17:08:54 [xdebug] ;用触发的形式去开启跟踪调试 get/post/cookie 中添加变量"XDEBUG_TRACE" xdebug.au ...
- 3.js模式-策略模式
1. 策略模式 策略模式定义一系列的算法,把它们封装起来,并且可以互相替换. var strategies = { isNonEmpty: function(value,errMsg){ if(val ...
- ffmpeg-20160628-git-bin.7z
ESC 退出 0 进度条开关 1 屏幕原始大小 2 屏幕1/2大小 3 屏幕1/3大小 4 屏幕1/4大小 S 下一帧 [ -2秒 ] +2秒 ; -1秒 ' +1秒 下一个帧 -> -5秒 f ...
- HDU 1823 Luck and Love(二维线段树)
之前只知道这个东西的大概概念,没具体去写,最近呵呵,今补上. 二维线段树 -- 点更段查 #include <cstdio> #include <cstring> #inclu ...
- 解决X64操作系统PL/SQL连接报错问题 make sure you have the 32 bits oracle client installed
Windows 64位下装Oracle 11g 64位,PLSQL Developer使用出现以下问题: 1.Database下拉框为空: 2.强制输入用户名.密码及Database,登录弹出: In ...
- Dynamic Invok Webservice
来源:网络,自己做修改 CSharpCodeProvider csc = new CSharpCodeProvider(); ICodeCompiler icc = csc.CreateCompile ...