Oracle Function: NVL
Description
The Oracle/PLSQL NVL function lets you substitute a value when a null value is encountered.
NVL函数是当出现空值时替换一个值
Syntax
NVL( string1, replace_with )
String1 |
The string to test for a null value. |
replace_with |
The value returned if string1 is null. |
Example
For example:
SELECT NVL(supplier_city, 'n/a') |
The SQL statement above would return 'n/a' if the supplier_city field contained a null value. Otherwise, it would return the supplier_city value. |
SELECT supplier_id, |
This SQL statement would return the supplier_name field if the supplier_desc contained a null value. Otherwise, it would return the supplier_desc. |
SELECT NVL(commission, 0) |
This SQL statement would return 0 if the commission field contained a null value. Otherwise, it would return the commission field. |
Frequently Asked Questions
Question: |
Answer: |
I tried to use the NVL function through VB to access Oracle DB. To be precise, SELECT NVL(Distinct (emp_name),'AAA'),................ I got an oracle error when I use distinct clause with NVL, but when I remove distinct it works fine. |
It is possible to the use the DISTINCT clause with the NVL function. However, the DISTINCT must come before the use of the NVL function. For example: SELECT distinct NVL(emp_name, 'AAA') |
Is it possible to use the NVL function with more than one column with the same function call? To be clear, if i need to apply this NVL function to more than one column like this: NVL(column1;column2 ...... , here is the default value for all ) |
Answer: You will need to make separate NVL function calls for each column. For example: SELECT NVL(table_name, 'not found'), NVL(owner, 'not found') |
Examine the TRAINING table as given below: Name Null? Type TRAINING_ID NOT NULL NUMBER(5) Which two SQL would execute successfully? (Choose two)
|
A, D. Use NVL function to provide an alternate value to a column when NULL. |
使用DISTINCT 的方法COUNT函数和NVL函数的区别:
NVL |
SELECT DISTINCT NVL(emp_name, 'AAA') |
COUNT |
SELECT COUNT(DISTINCT department) AS "Unique departments" |
From <https://www.techonthenet.com/oracle/functions/nvl.php>
Oracle Function: NVL的更多相关文章
- Oracle Function:COUNT
Description The Oracle/PLSQL COUNT function returns the count of an expression. The COUNT(*) functio ...
- Oracle Function:TO_CHAR
Description The Oracle/PLSQL TO_CHAR function converts a number or date to a string.将数字转换为日期或字符串 Syn ...
- oracle中空值null的判断和转换:NVL的用法
1.NULL空值概念 数据库里有一个很重要的概念:空值即NULL.有时表中,更确切的说是某些字段值,可能会出现空值, 这是因为这个数据不知道是什么值或根本就不存在. 2.NULL空值判断 空值不等同于 ...
- 问题:oracle nvl;结果:Oracle中的NVL函数
Oracle中的NVL函数 (2012-11-30 13:21:43) 转载▼ 标签: nvl oracle 分类: Oracle Oracle中函数以前介绍的字符串处理,日期函数,数学函数,以及转换 ...
- oracle function学习1
oracle function学习基层: 函数就是一个有返回值的过程. 首先 知道oracle 使用限制: 函数调用限制: 1. SQL语句中只能调用存储函数(服务器端),而不能调用客户端 ...
- Oracle中的NVL函数
Oracle中函数以前介绍的字符串处理,日期函数,数学函数,以及转换函数等等,还有一类函数是通用函数.主要有:NVL,NVL2,NULLIF,COALESCE,这几个函数用在各个类型上都可以. 下面简 ...
- oracle中的nvl(), nvl2()函数
nvl()函数是oracle/plpgsql中的一个函数,格式为:nvl(string1, replace_with) 功能:如果string1 位null,那么nvl()函数返回replace_wi ...
- Oracle中的NVL,NVL2,NULLIF以及COALESCE函数使用
首先注意空(null)值,空值加任何值都是空值,空值乘任何值也都是空值,依此类推. 1.NVL函数 NVL函数的格式如下:NVL(expr1,expr2) 含义是:如果oracle第一个参数为空那么显 ...
- [转载]Oracle中的NVL函数
Oracle中函数以前介绍的字符串处理,日期函数,数学函数,以及转换函数等等,还有一类函数是通用函数.主要有:NVL,NVL2,NULLIF,COALESCE,这几个函数用在各个类型上都可以. 下面简 ...
随机推荐
- Java虚拟机(一):JVM内存结构
所有的Java开发人员可能会遇到这样的困惑?我该为堆内存设置多大空间呢?OutOfMemoryError的异常到底涉及到运行时数据的哪块区域?该怎么解决呢?其实如果你经常解决服务器性能问题,那么这些问 ...
- 8 -- 深入使用Spring -- 3... 资源访问
8.3 资源访问 Spring 为资源访问提供了一个Resource接口,Spring框架本身大量使用了Resource来访问底层资源. Resource 本身是一个接口,是具体资源访问策略的抽象,也 ...
- iOS UTI(统一类型标识)
同一类型标识符(Uniform Type Identifier,UTI)代表IOS信息共享的中心组件.可以把它看成下一代的MIME类型.UTI是标识资源类型(比如图像和文本)的字符串,他们制定哪些类型 ...
- React Native(十一)——删除事件以及刷新列表
需求:删除列表中的某一项,但不刷新整个页面,底下的数据顺势而上(第一张是原始数据,第二张是删除掉"你会介今年"这条动态后显示的数据). 中间的过程比较曲折,只因为刚开始的时候自己只 ...
- C++ template —— 模板基础(一)
<C++ Template>对Template各个方面进行了较为深度详细的解析,故而本系列博客按书本的各章顺序编排,并只作为简单的读书笔记,详细讲解请购买原版书籍(绝对物超所值).---- ...
- (转载)Recyclerview | Intent与Bundle在传值上的区别 | 设置布局背景为白色的三种方法
用Recyclerview实现列表分组.下拉刷新以及上拉加载更多 http://www.jianshu.com/p/be62ce21ea57 Intent与Bundle在传值上的区别http://b ...
- Android 自定义 View 浅析
Android 自定义 View 浅析 概括 说到自定义 View ,就一定得说说 android 系统的UI绘制流程.再说这个流程之前,我们先看一下在每一个 activity 页面中我们的布局 ui ...
- springboot---->集成mybatis开发(二)
这里面我们介绍一下springboot集成mybatis完成一对多数据和一对一数据的功能.任何一个人离开你 都并非突然做的决定 人心是慢慢变冷 树叶是渐渐变黄 故事是缓缓写到结局 而爱是因为失望太多 ...
- jQuery的回调管理机制(二)
jQuery.extend({ /* * deferred对象的一大好处,就是它允许你自由添加多个回调函数. * $.ajax("test.html") .done(func ...
- laravel读取memcached缓存并做条件查询
public function onlineplayersource() { $res = $_POST['aoData']; $sEcho = 0; $iDisplayStart = 0; // 起 ...