oracle decode nvl nvl2 sign(即sin) 函数用法
2007-08-18 16:07
393 查看
select decode(p.xx,1,'no1',2,'no2') from person p
这样只能做等于,如果xx等于1就显示no1,等于2显示no2;
当我们需要做大于小于判断的时候就要借助sign函数了,select decode(sign(p.reportDate-p.finishDate),1,p.reportDate,0,p.reportDate,-1,'') from person p,如果reportDate减去finishDate是个正数则sign函数返回1,负数为-1,0为0,
NVL(EXPR1,EXPR2)
若EXPR1是NULL,则返回EXPR2,否则返回EXPR1.
SELECT NAME,NVL(TO_CHAR(COMM),'NOT APPLICATION') FROM TABLE1;
Use of the New NVL2 Function
Most of us are familiar with the NVL function which checks for the existence of NULL values. Oracle provides a new function called NVL2 which checks for the existence of NOT NULL. The syntax for this function is as follows.
NVL2(expr1,expr2,expr3);
If expr1 is not null then the function will return expr2. Otherwise, the function will return expr3. The expr1 can have any datatype and arguments expr2 and expr3 can be of any datatype other than LONG. The datatype of the return value is that of expr2.
这样只能做等于,如果xx等于1就显示no1,等于2显示no2;
当我们需要做大于小于判断的时候就要借助sign函数了,select decode(sign(p.reportDate-p.finishDate),1,p.reportDate,0,p.reportDate,-1,'') from person p,如果reportDate减去finishDate是个正数则sign函数返回1,负数为-1,0为0,
NVL(EXPR1,EXPR2)
若EXPR1是NULL,则返回EXPR2,否则返回EXPR1.
SELECT NAME,NVL(TO_CHAR(COMM),'NOT APPLICATION') FROM TABLE1;
Use of the New NVL2 Function
Most of us are familiar with the NVL function which checks for the existence of NULL values. Oracle provides a new function called NVL2 which checks for the existence of NOT NULL. The syntax for this function is as follows.
NVL2(expr1,expr2,expr3);
If expr1 is not null then the function will return expr2. Otherwise, the function will return expr3. The expr1 can have any datatype and arguments expr2 and expr3 can be of any datatype other than LONG. The datatype of the return value is that of expr2.
相关文章推荐
- Oracle 中 sign和decode 函数用法
- mysql数学函数之sign,sqrt用法
- oracle里面如何写case语句及decode and sign 函数用法
- oracle里面如何写case语句及decode and sign 函数用法
- LockWindowUpdate的函数的用法(不忽略消息,只是暂时不响应,但WM_SETREDRAW根本不接受重绘消息)
- getdate函数用法例子
- 三十四 assert()函数用法总结
- c++中的string常用函数用法
- [转]sprintf函数用法详解
- Oracle的substr函数简单用法
- 函数内Static初始化的用法
- 用来获取子串的两个函数substr和substring用法比较
- ROW_NUMBER() OVER函数的基本用法
- assert()函数用法总结
- sql开窗函数over()用法
- mysql一些函数常见的用法(group by、order by、....)(1)
- C语言中图形函数及其用法
- oracle中LAG()和LEAD()等分析统计函数的用法(统计月增长率)
- Oracle中集中对于NULL操作的函数NVL,NVL2,以及COALESCE的用法
- Oracle:函数Last,First的用法