zoukankan      html  css  js  c++  java
  • Oracle常用方法

    目录

    nvl

    一NVL函数是一个空值转换函数

    NVL(表达式1,表达式2)

    如果表达式1为空值,NVL返回值为表达式2的值,否则返回表达式1的值。 该函数的目的是把一个空值(null)转换成一个实际的值。其表达式的值可以是数字型、字符型和日期型。但是表达式1和表达式2的数据类型必须为同一个类型。

    对数字型: NVL( comm,0);

    对字符型 NVL( TO_CHAR(comm), 'No Commission')

    对日期型 NVL(hiredate,' 31-DEC-99')

    例子:

    select ename,NVL(TO_char(comm), ename||' is not a salesperson!') AS COMMISSION

    from emp

    二 NVL2(表达式1,表达式2,表达式3)

    如果表达式1为空,返回值为表达式3的值。如果表达式1不为空,返回值为表达式2的值。

    例如 NVL2(comm,'sal+comm',sal)

    NVL2函数测试comm

    如果comm为空,就返回sal 的值。如果 comm 不为空(null),就返回表达式 sal+comm的值。

    ROUND

    ROUND(x)函数将值x四舍五入之后保留了整数部分。
    +-------------+--------------+-------------+
    | ROUND(-6.6) | ROUND(-8.44) | ROUND(3.44) |
    +-------------+--------------+-------------+
    | -7 | -8 | 3 |
    +-------------+--------------+-------------+
    ROUND(x,y)根据参数y值,将参数x四舍五入后得到保留小数点后y位的值,x值的小数位不够y位的补零;如果y为负值,则保留小数点左边y位,先进行四舍五入操作,再将相应的位数值取零。
    +----------------+---------------+-----------------+-----------------+
    | ROUND(-6.66,1) | ROUND(3.33,3) | ROUND(88.66,-1) | ROUND(88.46,-2) |
    +----------------+---------------+-----------------+-----------------+
    | -6.7 | 3.330 | 90 | 100 |
    +----------------+---------------+-----------------+-----------------+
    截取数字 
    格式如下:ROUND(number[,decimals])
    其中:number 待做截取处理的数值
    decimals 指明需保留小数点后面的位数。可选项,忽略它则截去所有的小数部分,并四舍五入。如果为负数则表示从小数点开始左边的位数,相应整数数字用0填充,小数被去掉。需要注意的是,和trunc函数不同,对截取的数字要四舍五入。
    举例如下:

    Sql代码:

    SQL>   select   round(1234.5678,4)   from   dual;

    ROUND(1234.5678,4)
    ——————
    1234.5678

    SQL>   select   round(1234.5678,3)   from   dual;

    ROUND(1234.5678,3)
    ——————
    1234.568

    SQL>   select   round(1234.5678,2)   from   dual;

    ROUND(1234.5678,2)
    ——————
    1234.57

    SQL>   select   round(1234.5678,1)   from   dual;

    ROUND(1234.5678,1)
    ——————
    1234.6

    SQL>   select   round(1234.5678,0)   from   dual;

    ROUND(1234.5678,0)
    ——————
    1235

    SQL>   select   round(1234.5678,-1)   from   dual;

    ROUND(1234.5678,-1)
    ——————-
    1230

    SQL>   select   round(1234.5678,-2)   from   dual;

    ROUND(1234.5678,-2)
    ——————-
    1200

    SQL>   select   round(1234.5678,-3)   from   dual;

    ROUND(1234.5678,-3)
    ——————-
    1000

    附加:

    SQL>   select   round(45.923,-1)   from   dual;

    ROUND(45.923,-1)
    ——————-
    50

  • 相关阅读:
    sql 中 in 与 exist 的区别
    with as (cte common table expression) 公共表表达式
    配置连接数据库的方式
    Dispose 与 close 方法 的区别
    抽象类
    default
    什么叫无符号整型
    hdu 5187 zhx's contest [ 找规律 + 快速幂 + 快速乘法 || Java ]
    poj 2480 Longge's problem [ 欧拉函数 ]
    lightoj 1293
  • 原文地址:https://www.cnblogs.com/xiaoyinger/p/12195389.html
Copyright © 2011-2022 走看看