参考资料:http://docs.oracle.com/database/122/SQLRF/Functions.htm#SQLRF006

Single-row functions return a single result row for every row of a queried table or view. These functions can appear in select lists, WHEREclauses, START WITH and CONNECT BY clauses, and HAVING clauses.

单行函数返回查询表或视图的每一行的单一结果行。单行函数可以出现在SELECT列中,WHERE子句,START WITH 和CONNECT BY子句以及HAVING子句中。

NULL-Related Functions:

  The NULL-related functions facilitate null handling.

The NULL-related functions are:


  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.

    说明:  

        1.The arguments expr1 and expr2 can have any data type.

        参数expr1和expr2可以是任何数据类型。

        2. If their data types are different, then Oracle Database implicitly converts one to the other.

        如果俩参数数据类型不同,oracle数据库将进行隐式转换。

        3.If they cannot be converted implicitly, then the database returns an error.

        如果俩参数不能进行隐式转换,数据库将返回一个error。

        4.The implicit conversion is implemented as follows:(隐式转换如下)

          1>.If expr1 is character data, then Oracle Database converts expr2 to the data type of expr1 before comparing them and returns VARCHAR2 in the character set of expr1.

          如果expr1是字符数据,则数据库会将expr2转换为expr1的数据类型,并返回expr1的字符集中的VARCHAR2。

          2>.If expr1 is numeric, then Oracle Database determines which argument has the highest numeric precedence, implicitly converts the other argument to that data type, and returns that data type.

          如果expr1是数字,则Oracle数据库确定哪个参数具有最高的数字优先级,将另一个参数隐式转换为该数据类型,并返回该数据类型。

    用途:

        最主要的是格式化数据,比如涉及到数字的,不想出现空数据时,可用nvl(num,0)来得到0。由于  null+[或-,*,/]数字  等于null,所以在表达式中对可能为空的值要使用nvl。


  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.

    说明:

        1.The argument expr1 can have any data type. The arguments expr2 and expr3 can have any data types except LONG.

        参数expr1可以是任何数据类型,参数expr2和expr3可以是除了LONG类型外的任何数据类型。

        2.If the data types of expr2 and expr3 are different, then Oracle Database implicitly converts one to the other.

        如果参数expr2和expr3是不同的数据类型,数据库将会隐式的将其中一个转换为另一个。

        3.If they cannot be converted implicitly, then the database returns an error.

        如果俩参数不能进行隐式转换,数据库将返回一个error。

        4.If expr2 is character or numeric data, then the implicit conversion is implemented as follows:

        (如果expr2是字符或是数字数据,则隐式转换如下实现)

          1>.If expr2 is character data, then Oracle Database converts expr3 to the data type of expr2 before returning a value unless expr3 is a null constant. In that case, a data type conversion is not necessary, and the database returns VARCHAR2 in the character set of expr2.

          如果expr2是字符数据,数据库会将expr3(null除外)转换为expr2的数据类型。如果expr3为空常量,则不需要进行数据类型转换,数据库会返回expr2的字符集中的VARCHAR2。

          2>.If expr2 is numeric data, then Oracle Database determines which argument has the highest numeric precedence, implicitly converts the other argument to that data type, and returns that data type.

          如果expr2是数字数据,那么Oracle数据库将确定哪个参数具有最高的数字优先级,将另一个参数隐式转换为该数据类型,并返回该数据类型。


  NULLIF:

    语法:  NULLIF(expr1,expr2)

    功能:  NULLIF compares expr1 and expr2. If they are equal, then the function returns null. If they are not equal, then the function returns expr1. You cannot specify the literal NULL for expr1.

    说明:

        If both arguments are numeric data types, then Oracle Database determines the argument with the higher numeric precedence, implicitly converts the other argument to that data type, and returns that data type. If the arguments are not numeric, then they must be of the same data type, or Oracle returns an error.

        如果俩参数是数字数据类型,则Oracle数据库将确定具有较高数字优先级的参数,将另一个参数隐式转换为该数据类型,并返回该数据类型。 如果参数不是数字,则它们必须是相同的数据类型,否则Oracle返回一个error。

        The NULLIF function is logically equivalent to the following CASE expression:

CASE WHEN expr1 = expr2 THEN NULL ELSE expr1 END

  LNNVL:

    语法:  LNNVL(condition)

    功能:  LNNVL provides a concise way to evaluate a condition when one or both operands of the condition may be null.

         The function can be used in the WHERE clause of a query, or as the WHEN condition in a searched CASE expression.

         It takes as an argument a condition and returns TRUE if the condition is FALSE or UNKNOWN and FALSE if the condition is TRUE.

         LNNVL can be used anywhere a scalar expression can appear, even in contexts where the IS [NOTNULLAND, or OR conditions are not valid but would otherwise be required to account for potential nulls.

         Oracle Database sometimes uses the LNNVL function internally in this way to rewrite NOT IN conditions as NOT EXISTS conditions.

         In such cases, output from EXPLAIN PLAN shows this operation in the plan table output.

           The condition can evaluate any scalar values but cannot be a compound condition containing ANDOR, or BETWEEN.


  NANVL:

    语法:  NANVL(n2,n1)

    功能:

      The NANVL function is useful only for floating-point numbers of type BINARY_FLOAT or BINARY_DOUBLE.

      It instructs Oracle Database to return an alternative value n1 if the input value n2 is NaN (not a number). If n2 is not NaN, then Oracle returns n2.

      This function takes as arguments any numeric data type or any nonnumeric data type that can be implicitly converted to a numeric data type.

      Oracle determines the argument with the highest numeric precedence, implicitly converts the remaining arguments to that data type, and returns that data type.


Oracle Single-Row Functions(单行函数)——NULL-Related Functions的更多相关文章

  1. Oracle学习笔记_03_单行函数

    1.SQL函数: 单行函数.多行函数 单行函数:       操作数据对象       接受参数返回一个结果       只对一行进行变换       每行返回一个结果       可以转换数据类型  ...

  2. oracle 10g 学习之单行函数(5)

    目标 通过本章学习,您将可以: l  SQL中不同类型的函数. l  在 SELECT 语句中使用字符,数字和日期函数. l  描述转换型函数的用途. 字符函数 字符函数分为大小写控制函数和字符控制函 ...

  3. Oracle学习第二篇—单行函数

    1字符函数 length  字符长度 lengthb 字节长度 lower 变为小写 upper 变为大写 initcap 首字母大写 select Lower('xun Ying') 小写,Uppe ...

  4. oracle强化练习之单行函数

    1.      显示dname和loc中间用-分隔 Select dname ||'-'|| loc From dept; 2.      将部门名称左填充为10位 Select lpad( dnam ...

  5. SQL Fundamentals: Using Single-Row Functions to Customize Output使用单行函数自定义输出

    SQL Fundamentals || Oracle SQL语言 DUAL is a public table that you can use to view results from functi ...

  6. Netsuite Formula > Oracle函数列表速查(PL/SQL单行函数和组函数详解).txt

    PL/SQL单行函数和组函数详解 函数是一种有零个或多个参数并且有一个返回值的程序.在SQL中Oracle内建了一系列函数,这些函数都可被称为SQL或PL/SQL语句,函数主要分为两大类: 单行函数 ...

  7. Oracle中的单行函数

    Oracle中的单行函数 1 字符函数 UPPER()--将字符串转换为大写 SELECT UPPER('abc') FROM dual; LOWER()-将字符串转换为小写 SELECT LOWER ...

  8. Oracle单行函数笔记

    Oracle中单行函数的分类:1.字符函数substr():字符串截取select substr('我爱你,你知道么?',0,4) from dual执行结果:我爱你,length函数:字符串长度se ...

  9. Oracle Day2 过滤、排序、单行函数

    1.过滤和排序 SQL> --查询10号部门的所有员工信息 SQL> select * from emp ; 未选定行 SQL> ed SP2: 无法创建保存文件 "afi ...

随机推荐

  1. vue-router基本使用

    路由,其实就是指向的意思,当我点击页面上的home按钮时,页面中就要显示home的内容,如果点击页面上的about 按钮,页面中就要显示about 的内容.Home按钮  => home 内容, ...

  2. 计蒜客---N的-2进制表示

    对于十进制整数N,试求其-2进制表示. 例如,因为  1*1  +  1*-2  +  1*4  +  0*-8  +1*16  +  1*-32  =  -13  ,所以(-13)_10  =  ( ...

  3. 了解Redis过期策略及实现原理

    我们在使用redis时,一般会设置一个过期时间,当然也有不设置过期时间的,也就是永久不过期. 当我们设置了过期时间,redis是如何判断是否过期,以及根据什么策略来进行删除的. redis设置过期时间 ...

  4. 2017_CET4_CET6_正规段子——正规!正规!解析!段子手勿入!

    噫,2017年的四六级结束了,布吉岛宝宝们考得肿么样,反正本宝宝六级听力刚开始一阵挠头…… 天,神一般的FM信号,吃吃吃,擦擦擦,吃擦吃擦,吱吱吱…… 考完了就真完了,走出考场的那一刻,突然想起灰太狼 ...

  5. Service_name 和Sid的区别

    Service_name:该参数是由oracle8i引进的.在8i以前,使用SID来表示标识数据库的一个实例,但是在Oracle的并行环境中,一个数据库对应多个实例,这样就需要多个网络服务名,设置繁琐 ...

  6. B/S开发介绍

    b/s 的优势: 1.开发成本低 2.管理维护简单 3.产品升级便利 4.对用户的培训费用低 5.用户使用方便,出现故障的概率小 b/s 的不足: 1.安全性不足 2.客户端不能随心变化,受浏览器限制

  7. win10常见问题处理办法

    1.当笔记本连接wifi时,提示,无internet,安全,而手机能正常连接wifi时: cmd(需管理员权限)执行命令 netsh winsock reset 出现已重置,重启电脑 解决方法 2.当 ...

  8. jquery获取包含本身的元素

    我们知道,使用jquery获取一个元素内的所有元素非常容易,使用jQuery.html()就可以. 如果是js语法的话,使用domObj.innerHTML也很容易实现. 那么问题来了,要想获取包涵节 ...

  9. mysql 用存储过程插入11位 随机数

    BEGIN #Routine body goes here... ; ); ); ); ); ); ); ); ); ); ); ); ); ) DEFAULT ''; ); ); WHILE row ...

  10. vue 学习一些好的文档网址推荐

    相关文章   1. vue.js 2.x 文档  http://cn.vuejs.org https://vue.docschina.org/ 2. npm https://www.npmjs.com ...