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,这几个函数用在各个类型上都可以. 下面简 ...
随机推荐
- Xcode文件被锁定:The file ".xcodeproj" could not be unlocked
同事从svn上面checkout项目到本地,通过xcode打开的时候提示的这个问题. The file "xcodeproj" could not be unlocked. Cou ...
- [AX]AX2012 R2 HR Jobs, Positions, Department和Workers
部门.作业(Job的官方翻译)和位置(Position的官方翻译)是AX人力资源管理的基本组织元素,Job和Position在AX有的地方又称作工作和职位,其实这个翻译更为恰当. Job定义的是一个工 ...
- javascript 作用域、作用域链理解
JavaScript作用域就是变量和函数的可访问范围. 1.变量作用域 在JavaScript中,变量作用域分为全局作用域和局部作用域. 全局作用域 任何地方都可以定义拥有全局作用域的变量 1.没有用 ...
- curl 上传文件
1)在 php 5.5.0 之前,如果使用 @+文件路径的文件上传文件,具体看这里:http://www.cnblogs.com/tujia/p/5938463.html 2)php 5.5.0 之后 ...
- iOS开发-- 使用NSNumber将int、float、long等数据类型加入到数组或字典中
// 设置值 NSNumber *number=[NSNumber numberWithInt:45]; // 取值 NSLog(@"NSNumber %d",[number in ...
- Unity使用OpenGL绘制经纬线圈
using System.Collections; using System.Collections.Generic; using UnityEngine; public class LatLonGr ...
- Unity 蓝牙插件
1.新建一个Unity5.6.2f1工程,导入正版Bluetooth LE for iOS tvOS and Android.unitypackage2.用JD-GUI反编译工具查看unityandr ...
- 使用Html和ashx文件实现其简单的注册页面
记得上一次博客中实现的是其登录页面,其实学会了登录页面,注册页面自然就知道怎么写啦,都是一个意思的,但是今天不知道怎么个情况,写一个注册页面程序 中 一直在出错,大的问题小的问题一直出错,似乎是不在状 ...
- JQuery学习的尾声
今天是最后一天学习JQuery,上周我们在狠狠的学习JavaScript,然后在这周我们又把JQuery扼杀在了摇篮里面,纵然学习的太快我们导致我们知识不牢固,可是我们没有那么多的时间学习的如此详细, ...
- php危险的函数和类 disable_functions/class
phpinfo()功能描述:输出 PHP 环境信息以及相关的模块.WEB 环境等信息.危险等级:中 passthru()功能描述:允许执行一个外部程序并回显输出,类似于 exec().危险等级:高 e ...